Getting the External IP weirdness

Just starting out? Need help? Post your questions and find answers here.
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Getting the External IP weirdness

Post by Nituvious »

So, I am trying to return the External IP using a PHP script... I receive odd results though.
Results:

Code: Select all

HTTP/1.1 200 OK
Date: Wed, 17 Feb 2010 14:06:33 GMT
Server: Apache
X-Powered-By: PHP/5.1.6
Connection: close
Content-Type: text/html


PureBasic Code:

Code: Select all

InitNetwork()
userIP$ = StringField(GetHTTPHeader("http://nituvious.110mb.com/GetIP.php"),0, Chr(34))
Debug UserIP$
PHP script:

Code: Select all

<html>
<head>
<title>External IP</title>
</head>
<body>
<?php 
echo $_SERVER['REMOTE_ADDR']; 
?>
</body>
</html>
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Getting the External IP weirdness

Post by luis »

There is nothing wrong. The HTTP headers are not the page contents.
You need to parse the page contents.

Code: Select all

ReceiveHTTPFile("http://nituvious.110mb.com/GetIP.php", "c:\temp\result.txt")
Look into result.txt and you will find the IP there.
"Have you tried turning it off and on again ?"
A little PureBasic review
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Getting the External IP weirdness

Post by Nituvious »

Damn, I dont wanna download the file. :(
There's no other way?
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Getting the External IP weirdness

Post by luis »

Using a routine to download in memory. It's a shame PB doesn't have that as an option.

There are plenty on the forum. You can find one linked on my pages, under sources...
"Have you tried turning it off and on again ?"
A little PureBasic review
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Re: Getting the External IP weirdness

Post by Henrik »

Nituvious wrote:Damn, I dont wanna download the file. :(
There's no other way?
Hi This is what i do, this way the ip add only appear in the header of the GetIP.php file

php file "GetIP.php"

Code: Select all

<?php
//Gets the IP address
$ip = getenv("REMOTE_ADDR") ;
Header(":\"$ip\"");
?> 
pb get only ip addy

Code: Select all

InitNetwork()
UserIPViewer$="http://nituvious.110mb.com/GetIP.php"
UserIP$ = StringField(GetHTTPHeader(UserIPViewer$), 2, Chr(34))
Debug UserIP$

pb list hole header

Code: Select all

  InitNetwork()
  
  Header$ = GetHTTPHeader("http://nituvious.110mb.com/GetIP.php")
  
  Repeat 
    Index+1
    Line$ = StringField(Header$, Index, #LF$)
    Debug Line$
  Until Line$ = ""
Best Henrik
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Getting the External IP weirdness

Post by Nituvious »

Thank you! I wish I new more about PHP.
▓▓▓▓▓▒▒▒▒▒░░░░░
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Getting the External IP weirdness

Post by LuCiFeR[SD] »

personally I would do it this way...

Code: Select all

<?php
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP"); 
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR"); 
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR"); 
else $ip = "UNKNOWN"; 
header(":\"$ip\"");
?> 
PHP aint so bad to learn :P
Post Reply