Basic surfer information variables (from HTTP_SERVER_VARS)

Bill

80.***.***.***
1,469 days ago

Basic surfer information variables (from HTTP_SERVER_VARS)

Code:

<?php
$surfer_info[ip]=$HTTP_SERVER_VARS["REMOTE_ADDR"];
// $surfer_info[real_ip] will only contain something if the surfer used a transparent proxy
$surfer_info[real_ip]=$HTTP_SERVER_VARS["X_FORWARDED_FOR"];
$surfer_info[port]=$HTTP_SERVER_VARS["REMOTE_PORT"];
$surfer_info[browser_lang]=$HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"];
$surfer_info[user_agent]=$HTTP_SERVER_VARS["HTTP_USER_AGENT"];
$surfer_info[request_path]=$HTTP_SERVER_VARS["PATH_INFO"];
$surfer_info[request_query]=$HTTP_SERVER_VARS["QUERY_STRING"];
$surfer_info[request_method]=$HTTP_SERVER_VARS["REQUEST_METHOD"];
$surfer_info[http_referrer]=$HTTP_SERVER_VARS["HTTP_REFERER"];
?>

stalemate

202.***.***.***
1,449 days ago
I tried these codes in my site but to my surprise they didn't work. Plz help me.

Bill

80.***.***.***
1,449 days ago

stalemate;70:

I tried these codes in my site but to my surprise they didn't work. Plz help me.

It is just a row of variables, - it is up to you to decide how they are useful to your script and how to integrate them.

But if you want to see something happening any way, add

Code:

print_r($surfer_info);

to the bottom of the script (but before the closing ?>). Doing so will cause the script to show you what information the variables picked up.

stalemate

202.***.***.***
1,449 days ago
Good idea.This is working very well for me.It was so simple.No real coding.Its really showing the information for my likings.

penguinmama

12.***.***.***
1,440 days ago
Very cool! One can also stick phpinfo() into the bottom of the file (temporarily, and only for one's self, preferably!) to see ALL the variables.

Darkneoboi

68.***.***.***
1,435 days ago
One question, what does the print_r() command do? I know the print() command but not that one.

Bill

80.***.***.***
1,435 days ago

Darkneoboi;164:

One question, what does the print_r() command do? I know the print() command but not that one.

print_r() visualizes the given array in a neat format which supports multiple dimensions.

Example output:

Code:

Array
(
[phpcentral_com] => Array
(
[users] => Array
(
[0] => Bill
[1] => Darkneboi
[2] => stalemate
[3] => penguinmama
[4] => etc
[5] => etc
)

[facts] => Array
(
[0] => PHPCentral.com saves cats from trees.
[1] => Chuck Norris approves of PHPCentral.com.
)

)

)



Welcome to the forum, by the way!

penguinmama

12.***.***.***
1,435 days ago
Oh, that's nifty! I'll have to fiddle with that print_r (and arrays!) a little more!

Dismounted

59.***.***.***
1,435 days ago
Wow, print_r is very neat! I can't believe I never knew about it.

Darkneoboi

68.***.***.***
1,434 days ago
Yeah, it is pretty cool, i have know PHP for a while but this is the first time i have encountered that command. I may try to use it more often.

Logik

66.***.***.***
1,005 days ago
the variable "$HTTP_SERVER_VARS" did not work for me. I had to use "$_SERVER"

Code:

<?php
$surfer_info[ip]=$_SERVER["REMOTE_ADDR"];
// $surfer_info[real_ip] will only contain something if the surfer used a transparent proxy
$surfer_info[real_ip]=$_SERVER["X_FORWARDED_FOR"];
$surfer_info[port]=$_SERVER["REMOTE_PORT"];
$surfer_info[browser_lang]=$_SERVER["HTTP_ACCEPT_LANGUAGE"];
$surfer_info[user_agent]=$_SERVER["HTTP_USER_AGENT"];
$surfer_info[request_path]=$_SERVER["PATH_INFO"];
$surfer_info[request_query]=$_SERVER["QUERY_STRING"];
$surfer_info[request_method]=$_SERVER["REQUEST_METHOD"];
$surfer_info[http_referrer]=$_SERVER["HTTP_REFERER"];
print_r($surfer_info);
?>