Just starting out? Need help? Post your questions and find answers here.
-
Nituvious
- Addict

- Posts: 1027
- Joined: Sat Jul 11, 2009 4:57 am
- Location: United States
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>
▓▓▓▓▓▒▒▒▒▒░░░░░
-
luis
- Addict

- Posts: 3893
- Joined: Wed Aug 31, 2005 11:09 pm
- Location: Italy
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.
-
Nituvious
- Addict

- Posts: 1027
- Joined: Sat Jul 11, 2009 4:57 am
- Location: United States
Post
by Nituvious »
Damn, I dont wanna download the file.

There's no other way?
▓▓▓▓▓▒▒▒▒▒░░░░░
-
luis
- Addict

- Posts: 3893
- Joined: Wed Aug 31, 2005 11:09 pm
- Location: Italy
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...
-
Henrik
- Enthusiast

- Posts: 404
- Joined: Sat Apr 26, 2003 5:08 pm
- Location: Denmark
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

- Posts: 1027
- Joined: Sat Jul 11, 2009 4:57 am
- Location: United States
Post
by Nituvious »
Thank you! I wish I new more about PHP.
▓▓▓▓▓▒▒▒▒▒░░░░░
-
LuCiFeR[SD]
- 666

- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
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
