Jump to content

help understanding some $_SERVER variables..


Recommended Posts

Hi,

 

Could someone please tell me what all of these $+SERVER variables mean and/or do? I've been searching for a bit and can't seem to find anything, even on php.net's predefined variable list and I'm trying to find ways of logging ip's, browser versions etc.

 

  • $HTTP_X_FORWARDED_FOR
  • $HTTP_VIA
  • $HTTP_CLIENT_IP
  • $HTTP_PROXY_CONNECTION
  • $FORWARDED_FOR
  • $X_FORWARDED_FOR
  • $X_HTTP_FORWARDED_FOR
  • $HTTP_FORWARDED

 

None of them actually seem to work on my local server I receive this kind of error:

Notice: Undefined index: FORWARDED_FOR in C:\Program Files\wamp\www\counter.php on line 13

I'm presuming this is either because I don't have those server variables installed/enabled or they don't actually exist and have just sprouted up among the internet as a means of distracting us... ;)

 

any help would be great!

If you just put this in you code:

 

<?php 

echo '<pre>';
print_r($_SERVER);
echo '</pre>';
	  
?>

 

That will give a list of all the server variables, and what values they hold for that specific page.

To get an IP address, use $_SERVER['REMOTE_ADDR'];

Thanks.

The main one I undrstand are these two:

$_SERVER['REMOTE_ADDR']; //get ip
gethostbyaddr($_SERVER['REMOTE_ADDR']); //get ip hostname
$_SERVER['HTTP_REFERER']; //page referer

There was another way of getting the ip hostname, but I can't use it on my local server.

I'm just trying to figure out what the other's do, so I can decide if it's worth the hasle of trying to get them to work.. if I can.

I've already searched through that. None of them are listed on there, although a couple of people have used them in code examples, but no explaining what they do.

Also, how do I go about enabling the use of server values that aren't enabled at the moment?

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.