Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why isn't $_SERVER['HTTP_REFERER'] not working in functions

Status
Not open for further replies.

hos2

Programmer
May 6, 2002
418
NL
I try to log certain input atempts.

when I use
Code:
$ua=$HTTP_SERVER_VARS['HTTP_USER_AGENT'];
$qs=$_SERVER['QUERY_STRING'];
$ref=$_SERVER['HTTP_REFERER'];
$query="INSERT INTO SYSLOGTABLE(SLIP,SLHOST,SLDATE,SLUA,SLREFERER) 
VALUES('$host','$ip','$datum','$ua','$ref')";

it works fine
but when I define a function around it, then the $ua,$ref,$qs are empty in the database ????

Code:
function test($conn){
$ua=$HTTP_SERVER_VARS['HTTP_USER_AGENT'];
$qs=$_SERVER['QUERY_STRING'];
$ref=$_SERVER['HTTP_REFERER'];
$query="INSERT INTO SYSLOGTABLE(SLIP,SLHOST,SLDATE,SLUA,SLREFERER) 
VALUES('$host','$ip','$datum','$ua','$ref')";
}


I tried to define them global but that also didn't work :(
 
$ua will be empty because $HTTP_SERVER_VARS is only a global array. It's not available inside a function unless you use the global operator on it.

$_SERVER is superglobal and by definition available everywhere.

$ref could be blank simply because the browser isn't reporting referer logging. If the browser doesn't provide that information, it's simply not available.

Your query string building code doesn't reference $qs

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Some client firewalls also prevent things like HTTP_REFERER being sent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top