本文介绍了如何在Codeigniter中获取IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在执行以下代码以进行登录尝试&我要获取本地计算机的IP地址.
I am doing this following code for login attempt & i want get IP address of my local machine..
if ( !$this->session->userdata('login_attempts') )
{
$this->session->set_userdata('login_attempts', 0);
}
$attempts = ($this->session->userdata('login_attempts') + 1);
$this->session->set_userdata('login_attempts', $attempts);
// Check if the session.
if ( $this->session->userdata('login_attempts') > 4 )
{
echo 'hi....login attempt is over';
}
// Failed. So, update the session
echo $ip = $_SERVER['REMOTE_ADDR'];
// $ip_address = $this->input->ip_address1();
// return $ip_address;
echo $this->input->ip_address();
if ( ! $this->input->valid_ip($ip))
{
echo 'Not Valid';
}
else
{
echo 'Valid';
}
$this->db->update('loginattempts',array( 'login_attempts' =>$this->session->userdata('login_attempts') , 'lastLogin' =>date('Y-m-d H:i:s'),'ip'=>$ip = $_SERVER['REMOTE_ADDR'] ),array('login_id' =>1) );
echo ('hi....login attempt is'.$this->session->userdata('login_attempts'));
}
但是它显示了我本地计算机的错误IP地址.
but it show incorrect ip address of my local machine.
推荐答案
使用$this->input->ip_address();
也不要回显方程式.而是在另一行上回显:
Also, don't echo an equation. echo on another line instead:
$ip = $this->input->ip_address();
echo $ip;
这篇关于如何在Codeigniter中获取IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!