Can't get User's IP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Can't get User's IP

Post 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?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

use:

Code: Select all

getenv('REMOTE_ADDR')
instead.

hope that helps...

-Nay
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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..
Post Reply