Page 1 of 1

loging remote ip not working as i require it to

Posted: Thu Aug 20, 2009 11:43 am
by toasty525
Hi,

i am trying to log the users ip when they visit one of my sites

the setup is as follows:

i have one page on a site 1 that has the code:

Code: Select all

 
<?PHP
$ip=$_SERVER['REMOTE_ADDR'];
echo $ip;
?>
 
and another page on site 2 that has the code:

Code: Select all

 
<?PHP
include('http://site1.com/gettest.php');
?>
 
When a user visits site 2 i want site 1 to log there IP address but instead it only logs the IP address of the host for site 2.
Any help would be great thanks :D

Re: loging remote ip not working as i require it to

Posted: Thu Aug 20, 2009 11:58 am
by jackpf
I'd recommend using cURL or sockets to open the page on the second server. That way you can pass the user's ip address in the query string, or as a cURL paremeter.

Since the server is making the request to include the file, then the second server will obviously log the first server's IP address.

Re: loging remote ip not working as i require it to

Posted: Thu Aug 20, 2009 12:41 pm
by toasty525
I have found a simple way around it using HTML and an iframe:

Code: Select all

 
<iframe allowtransparency="true" src="http://site1.com/gettest.php" frameborder="0" scrolling="no"></iframe>
 
if i place the above HTML on site 2, site 1 is able to log the IP of the user instead of the IP of the host :)

Re: loging remote ip not working as i require it to

Posted: Thu Aug 20, 2009 1:09 pm
by jackpf
Ahh yeah, I forgot about that.

Another way would to put a link the script on server 1 in an <img> tag with a width and height of 0. Then when the browser goes the fetch to image, it'll execute the script on server 1.

Either way works.

Re: loging remote ip not working as i require it to

Posted: Thu Aug 20, 2009 8:52 pm
by McInfo
Another option is to pass the IP address through the query string.

Server 2:

Code: Select all

include 'http://server1/test.php?ip='.$_SERVER['REMOTE_ADDR'];
Server 1:

Code: Select all

$_GET['ip']
Edit: This post was recovered from search engine cache.

Re: loging remote ip not working as i require it to

Posted: Fri Aug 21, 2009 6:25 am
by jackpf
Oh yeah, I suppose you're using URL includes. I've never done that since I only do local includes, which uses the filesystem rather than HTTP...so you can't include query strings...

Forgot about that x_x