wapak777 Posted May 19, 2011 Share Posted May 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236883-getting-a-users-ip-address/ Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 When posting code, enclose it within . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/236883-getting-a-users-ip-address/#findComment-1217649 Share on other sites More sharing options...
wildteen88 Posted May 19, 2011 Share Posted May 19, 2011 You need to check that the variables $_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'] exist before using them. Quote Link to comment https://forums.phpfreaks.com/topic/236883-getting-a-users-ip-address/#findComment-1217651 Share on other sites More sharing options...
wapak777 Posted May 19, 2011 Author Share Posted May 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236883-getting-a-users-ip-address/#findComment-1217656 Share on other sites More sharing options...
wildteen88 Posted May 19, 2011 Share Posted May 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236883-getting-a-users-ip-address/#findComment-1217664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.