Jump to content


Photo

PHP to grab HTTP information


  • Please log in to reply
4 replies to this topic

#1 ndisdabest

ndisdabest
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 October 2006 - 12:29 AM

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!

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 06 October 2006 - 01:03 AM

just use...

print_r ( $_SERVER );


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


<?

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>';

?>


me!

#3 ndisdabest

ndisdabest
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 October 2006 - 01:17 AM

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!

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 06 October 2006 - 01:33 AM

What infomation exactly? Nothing is passed from one page to another, they are completely seperate requests.

#5 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 06 October 2006 - 01:37 AM

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!

<?

$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'] : '' );

?>


me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users