Add IP address in input text field

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 150
Location: Holland Rotterdam

Add IP address in input text field

Dear admin i `m thankfully for your support `just great`.
With both examples for <input type="text"> it shows only string(13) but not the whole ip-adress.

Code: Select all

<input type="text" name="from" class="form-control"  value="<?php var_dump($_SERVER['REMOTE_ADDR']); ?>"/></div>

Code: Select all

<input type="text" name="from" class="form-control"  value="<?php function getIP(){
  return getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?:
 getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?:
 getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR')?:'UNKNOWN IP';
}
$ip = getIP();

var_dump($ip); 
 ?>"/>
if i place the code without the <input type="text" then it is working normal.
What could i do more to show into the <input type="text" the whole ip-adress ???

Admin
I tested this code; it is working.

Code: Select all

<?php
//returns client ip address
function getIP(){
  return getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?:
 getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?:
 getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR')?:'UNKNOWN IP';
}
$ip = getIP();
?>
Your html content..
<input type="text" name="from" class="form-control"  value="<?php echo $ip; ?>"/>

JanMolendijk
Thank you so mutch stupido me i had to use:

Code: Select all

<?php echo $ip; ?>

Similar Topics