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
ph4nt4zm
Forum Newbie
Posts: 6 Joined: Mon Nov 14, 2005 2:49 pm
Post
by ph4nt4zm » Mon Nov 14, 2005 2:53 pm
I need help solving this code:
Code: Select all
function Dot2LongIP ($IPaddr)
{
if ($IPaddr == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 65536 + $ips[0]
*16777216); }
}
Thank you so' much.
Nathaniel
Forum Contributor
Posts: 396 Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA
Post
by Nathaniel » Mon Nov 14, 2005 2:56 pm
Why do you have a slash before the period in your "split" call?
I don't know what your problem is, but try replacing $ips = split ("\.", "$IPaddr"); with $ips = explode('.', $IPaddr);
And you don't need quotes around $IPaddr... just the variable is fine...
- Nathaniel
ph4nt4zm
Forum Newbie
Posts: 6 Joined: Mon Nov 14, 2005 2:49 pm
Post
by ph4nt4zm » Mon Nov 14, 2005 3:04 pm
I don't know much about PHP scripting. This is the code that a friend gaved me and I just want to make it work for my website, so' please, if you are kind to tell me the right final code.
Thanks.
Nathaniel
Forum Contributor
Posts: 396 Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA
Post
by Nathaniel » Mon Nov 14, 2005 3:05 pm
Do as I said, test the function, then tell us if it doesn't work.
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Mon Nov 14, 2005 3:08 pm
What are you trying to achieve with this code? Why are you using it? For what purpose?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Mon Nov 14, 2005 3:10 pm
If i get it right, the following (built-in) function does it for you:
http://www.php.net/ip2long
ph4nt4zm
Forum Newbie
Posts: 6 Joined: Mon Nov 14, 2005 2:49 pm
Post
by ph4nt4zm » Mon Nov 14, 2005 3:17 pm
wtf wrote: What are you trying to achieve with this code? Why are you using it? For what purpose?
I Just want to make it work, it's a simple code but I am stupid and I can't make it work, Appreciate all help given, THX!~
ph4nt4zm
Forum Newbie
Posts: 6 Joined: Mon Nov 14, 2005 2:49 pm
Post
by ph4nt4zm » Mon Nov 14, 2005 3:21 pm
Nathaniel wrote: Do as I said, test the function, then tell us if it doesn't work.
OK
This is how I entered it on my index.php let's say page:
Code: Select all
<?php
function Dot2LongIP ($IPaddr)
{
if ($IPaddr == "") {
return 0;
} else {
$ips = explode('.', $IPaddr);
return ($ips[3] + $ips[2] * 256 + $ips[1] * 65536 + $ips[0]
*16777216); }
}
It's not working now, what to do?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Mon Nov 14, 2005 3:32 pm
You're missing a call to actually execute that function...
Eg:
Code: Select all
<?php
echo Dot2LongIP($_SERVER['REMOTE_ADDR'];
?>
ph4nt4zm
Forum Newbie
Posts: 6 Joined: Mon Nov 14, 2005 2:49 pm
Post
by ph4nt4zm » Mon Nov 14, 2005 4:02 pm
I'm interested in inputing the Long IP Number (long2ip) and resulting the IP Adress.
For Example: I want to know Long IP Number: 0201327359 what is the IP adress?
Thanks alot.
trukfixer
Forum Contributor
Posts: 174 Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA
Post
by trukfixer » Mon Nov 14, 2005 4:04 pm
May I recommend using the php manual? if you go here :
http://us2.php.net/manual/en/function.ip2long.php
and scroll down a little bit and *READ* (RTFM!) you would see another function just below it called long2ip to do the exact opposite.
ph4nt4zm
Forum Newbie
Posts: 6 Joined: Mon Nov 14, 2005 2:49 pm
Post
by ph4nt4zm » Mon Nov 14, 2005 4:08 pm
Thanks Guys.
Made it.
Case closed!
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon Nov 14, 2005 4:12 pm
The PHP manual is your best friend. No other language has such a helpful manual (I'm serious. Every try using the Perl manual?).