Page 1 of 1

Can't get User's IP

Posted: Mon Sep 08, 2003 7:32 am
by EricS
I trying to get the user's IP address as they submit their name and email address to my newsletter. Here's my code

Code: Select all

<?php

$p_name  = trim(strip_tags($_POST&#1111;'firstname']));
$p_email = trim(strip_tags($_POST&#1111;'email']));

$message  = 'This is a notice of a new subscriber to "Internet Marketing Brief"'."\n\n";
$message .= 'NAME='.$p_name."\n";
$message .= 'EMAIL='.$p_email."\n";
$message .= 'IP='.$_SERVER&#1111;'REMOTE_ADDR']."\n";
$message .= 'DATE='.date('m-d-Y');

mail('eric@omicentral.com', 'New subscriber', $message, 'FROM:subscribe@omicentral.com');

?>
I keep getting the IP address for the server instead of the user. Any idea?

Posted: Mon Sep 08, 2003 7:46 am
by Nay
use:

Code: Select all

getenv('REMOTE_ADDR')
instead.

hope that helps...

-Nay

Posted: Mon Sep 08, 2003 10:57 am
by m3rajk
is this being called by a diff script on the server the user never sees?
i ask becasue $_SERVER[REMOTE_ADDR]; works for me.

if it's being called by a diff script then it IS working fine. the issue is that the other script is on your server

Posted: Mon Sep 08, 2003 4:25 pm
by Stoker
actually to be correct, $_SERVER is an associcative array and you should not type the key-strings without quotes in such, as that can/should be intepreted as a defined constant, PHP is pretty good at guessing that you where just lazy, but it is a bad programming practice not to do it correctly to avoid unexpected functionality in the future..
$_SERVER['REMOTE_ADDR']

Sometimes I whish PHP had some configure options that would disable all such "convenience" functionality and make it much more strict, it would likely increase speed and decrease possibilities for bugs..