Page 1 of 1

ip2long

Posted: Mon Aug 13, 2007 7:07 am
by pedroz
I am facing the following problem:

_ I have a file in my server checking the ip's from the visitors working perfectly but I am figuring an error in following code:

Code: Select all

$pagesource = file_get_contents('http://myserver/ip.php');
echo $pagesource; //correctly displayed ip: xxx.xxx.xxx.xxx
$ip = explode(":",str_replace(' ', '', $pagesource));
echo $ip[1]; //correctly displayed xxx.xxx.xxx.xxx

echo ip2long($ip[1]); //ERROR! nothing displayed...
I have php 5.2.3 and if I use
$ip[1]="127.0.0.1";
echo ip2long($ip[1]);
It works FINE

What is my problem?

Posted: Mon Aug 13, 2007 7:12 am
by feyd
I would imagine you have extraneous information in the string you aren't seeing. Look at the page source. Potentially use var_dump() too.

Posted: Mon Aug 13, 2007 10:30 am
by s.dot
Yes. Most likely some whitespace. Use $pagesource = trim($pagesource); after your file_get_contents() line. See of that works out for you. If not, do what feyd suggested. (or perhaps the other way around! :))

Posted: Mon Aug 13, 2007 1:26 pm
by pedroz
Thanks! I tried trim but it still does not work.

This driving me crazy. Any chance of any type of configuration in php.ini blocking this? :)

Posted: Mon Aug 13, 2007 1:30 pm
by RobertGonzalez
var_dump() it and see what is really in that variable.