Jump to content

Archived

This topic is now archived and is closed to further replies.

ndisdabest

PHP to grab HTTP information

Recommended Posts

Hi all --

Easy question, I'm sure...  and I'm guessing it's probably on the board somewhere, but I don't know what to look for, so I'll ask.

I'm looking to grab all HTTP information (URL Referrals, Variables, Querystrings, etc) that comes along with a hit to my page.  I did this with some simple code once before, but I don't remember what it is.

Any help would be greatly appreciated!

Thanks!

Share this post


Link to post
Share on other sites
just use...

[code]print_r ( $_SERVER );[/code]


To see what you want to use, or you can do this to loop each one so you know each name value pair!


[code]<?

echo '<pre>';

foreach ( $_SERVER AS $name => $value )
{
if ( $name == 'ALL_HTTP' )
{
echo "\t\$_SERVER['" . $name . "'] = array ( \r\n";

$value = preg_split ( "/\r?\n/", $value, -1, PREG_SPLIT_NO_EMPTY );

foreach ( $value AS $all )
{
echo "\t\t\$_SERVER['" . substr ( $all, 0, strpos ( $all, ':' ) ) . "'] = '" . substr ( $all, ( strpos ( $all, ':' ) + 1 ) ) . "';\r\n";
}

echo "\t};\r\n";
}
else
{
echo "\$_SERVER['" . $name . "'] = '" . $value . "';\r\n";
}
}

echo '</pre>';

?>[/code]


me!

Share this post


Link to post
Share on other sites
That is great code...  however, I am looking to grab information about the page the users are coming FROM.  Any way to do this?

Thanks again for all your help!

Share this post


Link to post
Share on other sites
What infomation exactly? Nothing is passed from one page to another, they are completely seperate requests.

Share this post


Link to post
Share on other sites
I put that example so you can see what you want to grab, so say you want the IP, REFERER (if referer), QUERY STRING, you use any of the $_SERVER variables to get that information!

[code]<?

$ip = $_SERVER['REMOTE_ADDR'];
$referer = ( ! empty ( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '' );
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$query_string = ( ! empty ( $_SERVER['QUERY_STRING'] ) ? $_SERVER['QUERY_STRING'] : '' );

?>[/code]


me!

Share this post


Link to post
Share on other sites

×

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.