ip2long

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

ip2long

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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! :))
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Post 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? :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

var_dump() it and see what is really in that variable.
Post Reply