简体   繁体   English

如何查看我的IP地址?

[英]How can I check my ip address?

I have a login function where I am using user name and password to login. 我有一个登录功能,使用用户名和密码登录。 Now I want to check the id address also.My ip addresses are in another table where id is matched with the rank. 现在我还要检查id地址,我的ip地址在另一个表中,其中id与等级匹配。 I need to know how can I check ip in same function of my controller.How can I write my functions ? 我需要知道如何在控制器的同一功能中检查ip。如何编写功能?

Ip address table:               login table:

id  ip_address                  ID uname pass      rank
2   98.231.50.890               1  admin admin321   1

Here is my login function. 这是我的登录功能。 There is a filed rank. 有一个提成的等级。 IF rank is 1. User can login easily other wise function will check that ip address. 如果等级为1,则用户可以轻松登录其他智能功能,将检查该IP地址。

public function loginAction() {
        $postArray = $this->input->post();
        $table= 'login';
        //$user_type=1;
        if (!empty($postArray)) {
            $result = $this->m_common->login_with_password_string($postArray['user_name'], $postArray['user_pass'], $table);
            if (!empty($result->ID) && isset($result->ID)) {
                $this->session->set_userdata('user_id',$result->ID);
                $this->session->set_userdata('user_name',$result->uname);
                $this->session->set_userdata('theme',$result->theme);
                $this->session->set_userdata('logged_in',1);
                //$this->is_logged_in($this->session->userdata('logged_in'));
                redirect(site_url(ADMIN.'/dashboard/view_player'));
//                echo 'Hello';
            } else {

                 $data['message']="Incorrect Username or Password";
                  $this->titlebackend("View Players");
                 $this->load->view('v_login',$data);
            }
        }
    }

你可以用这个

$ip = $this->input->ip_address(); echo $ip;

Step 1 , write an get ip address function like following 步骤1,编写如下的获取ip地址功能

 function getRealIpAddr(){
  if(!empty($_SERVER['HTTP_CLIENT_IP'])){
      $ip = $_SERVER['HTTP_CLIENT_IP'];
  }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  }else{
      $ip = $_SERVER['REMOTE_ADDR'];
  }
  return $ip;
}

Step 2 , Query all ip_address as an array from ip address table 步骤2,从ip地址表中查询所有ip_address作为数组

$ips = array(); // assume this result from you database
if(in_array($ip,$ips)){
  // true
}
// or you can loop the ips array
foreach(ips as $lip){
  if($lip == $ip){
     //true
     break;
  }
}

For you case i suggest you convert ip to long type before stored into database , because it will improve the query performance when ip tables have the large data. 对于您的情况,我建议您先将ip转换为long类型,然后再存储到数据库中,因为当ip表包含大量数据时,它将提高查询性能。

$long = ip2long($ip);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在PHP中检查我自己的IP地址 - How to check my own ip address in php 我如何将我的IP地址更改为给定地址并访问网站 - How i change my ip address to a given address and access a website 如何使用本地IP地址而不是localhost访问数据库mysql服务器 - How can I access my database mysql server using my local ip address instead of using localhost 您好,我想将我的IP地址与IP文本列表进行匹配。 怎么办? 而我的IP地址与我的IP文本列表中的IP地址是正确的 - Hello i want to match my ip address with ip text list. How would it do? Whereas my ip address with ip address in my ip text list is correct 如何使用PHP简化IP地址? 尝试long2ip(ip2long(address)) - How can I simplify an IP address using PHP? Trying long2ip(ip2long(address)) 如何检查用户输入是否是有效的 IP 地址? - How do I check if a users input is a valid IP address or not? 如何在WordPress中woocommerce中基于IP地址更改产品的货币? - How can I change my product's currency based on the IP address in woocommerce in wordpress? 如何防止我的IP地址被Ebay禁止? - How can I prevent my IP address from getting banned by Ebay? 如何查看并上传带有地址的图片? - How can i check and upload image with an address? 如何向 IP 地址 PHP 发出 CURL 请求? - How can I make a CURL request to IP Address PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM