PHPCentral.com

Go Back   PHPCentral.com > PHP Code Depository > Networking Snippets
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Welcome to the PHPCentral.com forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

Reply
 
Thread Tools Search this Thread
Old 08-28-2006, 06:23 PM   #1
Bill
Administrator
 
Bill's Avatar
 
Join Date: Aug 2006
Posts: 183
Bill has disabled reputation
Default 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"]; ?>
Bill is offline   Reply With Quote
Old 09-17-2006, 05:34 PM   #2
stalemate
Junior Member
 
Join Date: Sep 2006
Posts: 20
stalemate is on a distinguished road
Default

I tried these codes in my site but to my surprise they didn't work. Plz help me.
stalemate is offline   Reply With Quote
Old 09-17-2006, 05:50 PM   #3
Bill
Administrator
 
Bill's Avatar
 
Join Date: Aug 2006
Posts: 183
Bill has disabled reputation
Default

Quote:
Originally Posted by stalemate View Post
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.
Bill is offline   Reply With Quote
Old 09-18-2006, 03:00 AM   #4
stalemate
Junior Member
 
Join Date: Sep 2006
Posts: 20
stalemate is on a distinguished road
Default

Good idea.This is working very well for me.It was so simple.No real coding.Its really showing the information for my likings.
stalemate is offline   Reply With Quote
Old 09-27-2006, 04:54 AM   #5
penguinmama
Member
 
Join Date: Sep 2006
Posts: 62
penguinmama is on a distinguished road
Default

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.
penguinmama is offline   Reply With Quote
Old 10-01-2006, 11:53 PM   #6
Darkneoboi
Junior Member
 
Join Date: Oct 2006
Posts: 18
Darkneoboi is on a distinguished road
Default

One question, what does the print_r() command do? I know the print() command but not that one.
Darkneoboi is offline   Reply With Quote
Old 10-02-2006, 02:15 AM   #7
Bill
Administrator
 
Bill's Avatar
 
Join Date: Aug 2006
Posts: 183
Bill has disabled reputation
Default

Quote:
Originally Posted by Darkneoboi View Post
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!
Bill is offline   Reply With Quote
Old 10-02-2006, 04:10 AM   #8
penguinmama
Member
 
Join Date: Sep 2006
Posts: 62
penguinmama is on a distinguished road
Default

Oh, that's nifty! I'll have to fiddle with that print_r (and arrays!) a little more!
penguinmama is offline   Reply With Quote
Old 10-02-2006, 07:59 AM   #9
Dismounted
Member
 
Join Date: Sep 2006
Posts: 53
Dismounted is on a distinguished road
Default

Wow, print_r is very neat! I can't believe I never knew about it.
Dismounted is offline   Reply With Quote
Old 10-02-2006, 09:10 PM   #10
Darkneoboi
Junior Member
 
Join Date: Oct 2006
Posts: 18
Darkneoboi is on a distinguished road
Default

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.
Darkneoboi is offline   Reply With Quote
Old 12-05-2007, 08:20 PM   #11
Logik
Junior Member
 
Logik's Avatar
 
Join Date: Nov 2007
Posts: 5
Logik is on a distinguished road
Default

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); ?>
Logik is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT. The time now is 12:38 AM.

Contact Us - Site Map - Top
Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC3