Jump to content

getting a users ip address??


wapak777

Recommended Posts

Hi. my browser ist telling me there are errors on line 3 and 4 for my code. It says summin like Notice: HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR are unidentified:

 

below is the code see if you can spot anything btw i copied down the code from beginner php tutorial 66 if you type that into youtube :) .

<?php

$http_client_ip = $_SERVER['HTTP_CLIENT_IP'];
$http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
$remote_addr = $_SERVER['REMOTE_ADDR'];

if (!empty($http_client_ip)){
   $ip_addr = $http_client_ip;
   
}else if(!empty($http_x_forwarded_for)){
   $ip_addr = $http_x_forwarded_for;
}else{
   $ip_addr = $remote_addr;
}

echo $ip_addr;
?>

 

Thanks :)

 

MOD EDIT: code tags added.

Link to comment
https://forums.phpfreaks.com/topic/236883-getting-a-users-ip-address/
Share on other sites

Yh I know I was thinking they didn't actually exist but i saw this guy making a tutorial was using them and he didn't get any errors... I gonna check again that he didn't require or include another script before using them. and btw sorry about not including the code tags around the code :)

Yh I know I was thinking they didn't actually exist but i saw this guy making a tutorial was using them and he didn't get any errors...

They must of either configured php to not display errors or set error_reporting so it ignores notices.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.