Page 1 of 1

Getting the External IP weirdness

Posted: Wed Feb 17, 2010 3:06 pm
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>

Re: Getting the External IP weirdness

Posted: Wed Feb 17, 2010 3:29 pm
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.

Re: Getting the External IP weirdness

Posted: Wed Feb 17, 2010 4:22 pm
by Nituvious
Damn, I dont wanna download the file. :(
There's no other way?

Re: Getting the External IP weirdness

Posted: Wed Feb 17, 2010 4:27 pm
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...

Re: Getting the External IP weirdness

Posted: Wed Feb 17, 2010 5:04 pm
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

Re: Getting the External IP weirdness

Posted: Thu Feb 18, 2010 11:56 am
by Nituvious
Thank you! I wish I new more about PHP.

Re: Getting the External IP weirdness

Posted: Thu Feb 18, 2010 8:15 pm
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