简体   繁体   中英

CodeIgniter ip_address() always returns 0.0.0.0

My Codeigniter sessions have been dying a-lot lately. So I went and had a look at my database and I saw that all the sessions have ip_address 0.0.0.0 and some have useragent 0

So I checked my $CI->input->ip_address() function and saw that it always returns 0.0.0.0 event thought $_SERVER['REMOTE_ADDR'] returns an IP address that is valid in $CI->input->valid_ip($ip) .

Does this have anything to do with my sessions dying?

I also read that sessions tend to die when the user-data reaches 4K. It might be part of it as I give every page an ID in the session which is never removed. I think its not the issue because 90% of the activity is via 1 page and AJAXs (I already added an AJAX session fix).

EDIT: I am using CI version 2.1.4.

input->ip_address() is defined incorrectly in system/core/input.php.
On line 351 change it to $this->ip_address = $this->server('REMOTE_ADDR');

So, Im not sure how it happened, but apparently the var " REMOTE_ADDR " was coming in lowercase and should be uppercase. So adding strtoupper() to input->server() on the var $index fixed my problem for now....

Very strange issue...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM