Jump to content

Recommended Posts

I am using the following two methods now to capture above mentioned info:

[code]$ip_address = $_SERVER['REMOTE_ADDR'];

$user_browser = $_SERVER['HTTP_USER_AGENT'];[/code]

This user info is captured and sent in an email to me and works perfectly on our Test Server. However, on the Live Server this does not get captured (I get an email with a blank).

What could be the cause of this?
[code]
<html>
<body>
<?

$ip_address = $_SERVER['REMOTE_ADDR'];

$user_browser = $_SERVER['HTTP_USER_AGENT'];

//add From: header
$headers = "From: \"Online Survey\" webserver@localhost\r\n";

//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";

//unique boundary
$boundary = uniqid("HTMLDEMO");

//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/alternative" .
   "; boundary = $boundary\r\n\r\n";

//message to people with clients who don't understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";

//HTML version of message
$headers .= "--$boundary\r\n" .
   "Content-Type: text/html; charset=ISO-8859-1\r\n" .
   "Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("IP Address: $ip_address Browser: $user_browser"))

//send message
mail("yana@greatgulfhomes.com,yanochka_@hotmail.com", "Online Survey", "", $headers);

?>
</body>
</html>
[/code]

On the live server no values are returned for IP address and has been the case all the time. On the test server it works fine.

My manager just gave me a tip that it might have to do with different versions of PHP that we have installed on Test and Live Servers.

And told me to use [code]$ip_address = $HTTP_SERVER_VARS['REMOTE_ADDR'];[/code] instead of [code]$ip_address = $_SERVER['REMOTE_ADDR'];[/code]

However, it still does not work on the Live Server........  ::)
user using proxy may not get detected right.

try this, i'm not sure it's work but try anyway.

if (getenv('HTTP_X_FORWARDED_FOR')) {
       $ip_address = getenv('HTTP_X_FORWARDED_FOR');
   } else {
       $ip_address = getenv('REMOTE_ADDR');
   }
This is the code I use to do a similar function. It works about 90% of the time:
[code]<?php
    if ($_SERVER["HTTP_X_FORWARDED_FOR"] != "")
{
        $IP = $_SERVER["HTTP_X_FORWARDED_FOR"];
        $proxy = $_SERVER["REMOTE_ADDR"];
        $host = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]);
    }
else
{
        $IP = $_SERVER["REMOTE_ADDR"];
        $host = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
    }
?>[/code]

I believe I got this code from a different forum about 4 or 5 years ago...

Ken
The method hvle posted is probably the best your going to get. Just remember though that some clients will not show up or will have fake ip. Also be aware that just because your getting hits from a certain ip doesn't mean it is the same client. I have 8 computers in my house, all of which share 1 ip.
Wow thanks!  :-*

This code works for me on the Test and Live server!!!!!!!!!!

[code]if (getenv('HTTP_X_FORWARDED_FOR')) {
       $ip_address = getenv('HTTP_X_FORWARDED_FOR');
   } else {
       $ip_address = getenv('REMOTE_ADDR');
   }[/code]

Could anyone explain to me what is the difference between this code and the one I used?????????
[quote author=thorpe link=topic=100191.msg395130#msg395130 date=1152626082]
The method hvle posted is probably the best your going to get. Just remember though that some clients will not show up or will have fake ip. Also be aware that just because your getting hits from a certain ip doesn't mean it is the same client. I have 8 computers in my house, all of which share 1 ip.
[/quote]

I am not really concerned how useful this IP address will be! My task was to create an online survey...which was supposed to be anonymous. So anonymous means to me that nothing should be captured......at all! :)
Yeah apparently the Live Server has an older version of PHP (3 or so) and the Test Server uses the newer version 4...

Now that this is working for me, I wonder how useful this is at all???????

The test server returns one IP address for me (10.243.102.136) while the Live Server returns a different IP address (216.191.52.74)...
What is the reason for that???????????
[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
The test server returns one IP address for me (10.243.102.136) while the Live Server returns a different IP address (216.191.52.74)...
[/quote]
Do you have a dynamic IP. I've read that at some ISPs the IP change at every request.

[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
Yeah apparently the Live Server has an older version of PHP (3 or so) and the Test Server uses the newer version 4...
[/quote]
If it's your server I would upgrade PHP to version 4 (or 5 if you wish). The reason why you need to use $HTTP_SERVER_VARS instead of $_SERVER is that $_SERVER was first implemented in PHP4.
[quote author=Daniel0 link=topic=100191.msg395144#msg395144 date=1152626744]
[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
The test server returns one IP address for me (10.243.102.136) while the Live Server returns a different IP address (216.191.52.74)...
[/quote]
Do you have a dynamic IP. I've read that at some ISPs the IP change at every request.

[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
Yeah apparently the Live Server has an older version of PHP (3 or so) and the Test Server uses the newer version 4...
[/quote]
If it's your server I would upgrade PHP to version 4 (or 5 if you wish). The reason why you need to use $HTTP_SERVER_VARS instead of $_SERVER is that $_SERVER was first implemented in PHP4.
[/quote]

It's not my server - it's the company's.
[quote author=yana link=topic=100191.msg395148#msg395148 date=1152626924]
[quote author=Daniel0 link=topic=100191.msg395144#msg395144 date=1152626744]
[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
The test server returns one IP address for me (10.243.102.136) while the Live Server returns a different IP address (216.191.52.74)...
[/quote]
Do you have a dynamic IP. I've read that at some ISPs the IP change at every request.

[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
Yeah apparently the Live Server has an older version of PHP (3 or so) and the Test Server uses the newer version 4...
[/quote]
If it's your server I would upgrade PHP to version 4 (or 5 if you wish). The reason why you need to use $HTTP_SERVER_VARS instead of $_SERVER is that $_SERVER was first implemented in PHP4.
[/quote]

It's not my server - it's the company's.
[/quote]
Tell them to upgrade, it's an old version.

[quote author=thorpe link=topic=100191.msg395146#msg395146 date=1152626878]
10.243.102.136 appears to be your internal NIC address, while the other is your public IP.
[/quote]
Ah, yes of course, he will see his internal IP address when he runs the script on localhost.
[quote author=yana link=topic=100191.msg395148#msg395148 date=1152626924]
[quote author=Daniel0 link=topic=100191.msg395144#msg395144 date=1152626744]
[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
The test server returns one IP address for me (10.243.102.136) while the Live Server returns a different IP address (216.191.52.74)...
[/quote]
Do you have a dynamic IP. I've read that at some ISPs the IP change at every request.

[quote author=yana link=topic=100191.msg395140#msg395140 date=1152626512]
Yeah apparently the Live Server has an older version of PHP (3 or so) and the Test Server uses the newer version 4...
[/quote]
If it's your server I would upgrade PHP to version 4 (or 5 if you wish). The reason why you need to use $HTTP_SERVER_VARS instead of $_SERVER is that $_SERVER was first implemented in PHP4.
[/quote]

It's not my server - it's the company's.
[/quote]

And neither Live or Test server appears to use a dynamic IP address.....because I've tested it now a few times and every time I get the exact same value for IP Address on Live and Test server.

Well, anyhow. It works now.
[quote author=yana link=topic=100191.msg395151#msg395151 date=1152627093]
And neither Live or Test server appears to use a dynamic IP address.....because I've tested it now a few times and every time I get the exact same value for IP Address on Live and Test server.
[/quote]

I meant you, but see above for the explanation.
Actually what I meant is that now my code works on the Test AND Live Server. I've used the following code to capture the IP Address:

[code]if (getenv('HTTP_X_FORWARDED_FOR')) {
        $ip_address = getenv('HTTP_X_FORWARDED_FOR');
    } else {
        $ip_address = getenv('REMOTE_ADDR');
    }[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.