Jump to content

PHP to grab HTTP information


ndisdabest

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!
Link to comment
https://forums.phpfreaks.com/topic/23132-php-to-grab-http-information/
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!
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!

Archived

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

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