J-LO
J-LO

Reputation: 229

Attempting to gather user's IP address with PHP

I'm trying to get the user's ip address once the page loads with the following:

<?php  
    $user_ip = $_SERVER['REMOTE_ADDR']; 
?>

and trying to print the value like so:

<input id="ip" name="ip"  value="<?php $user_ip = echo ($user_ip); ?>" type="hidden">

for some reason it won't print. Any ideas?

Upvotes: 0

Views: 143

Answers (1)

kmas
kmas

Reputation: 6439

If you assign the echo result, it will print nothing :

<input id="ip" name="ip"  value="<?php echo ($user_ip); ?>" type="hidden">

If you want to display it to user :

<input id="ip" name="ip"  value="<?php echo ($user_ip); ?>" type="text">

Upvotes: 6

Related Questions