Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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