I’m simply trying to store the current page a user is viewing in a DB. When the page loads, I insert $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING'] into my DB, but only the page (e.g. index.php?) is showing up, without the query string (I have verified that there IS a query string in the URL).
I tried $_SERVER['PHP_SELF'] with the same results.
EDIT TO ADD:
Here is the dump of $_SERVER:
Array
(
. . .
[REQUEST_METHOD] => GET
[QUERY_STRING] => view=scores&yr=2010&wk=1
[REQUEST_URI] => /index.php?view=scores&yr=2010&wk=1
. . .
)
So the query string is present in the array, even as part of REQUEST_URI. So my query…
mysql_query("insert into clickstream
(user_id, page)
values
(" . $_SESSION['user_id'] . ", '" . mysql_real_escape_string($_SERVER['REQUEST_URI']) . mysql_real_escape_string($_SERVER['QUERY_STRING']) . "');")
or die('mysql error: ' . mysql_error());
…should actually insert the query string twice, instead of no times!
Thoughts?
ADDED THOUGHT: Is it possible the MySQL DB strips everything from the input beyond the ?? The field is varchar.
UPDATE W/ PARTIAL SOLUTION: Changing the SQL input to just $_SERVER['QUERY_STRING'] (without REQUEST_URI) successfully input the query string. Thus, it leads me to believe that either PHP or MySQL was stripping everything from the input string after the ?. So the input params were correct; the result just got truncated.
Does anyone know why this might be the case?
Thanks for the feedback, particularly @nachito. The problem has been isolated to MySQL, not PHP. The output from PHP is correct, but MySQL is stripping everything from the URL after
?upon insertion into the database.