0

I'm using the following in my php code:

$file="query.txt";
$f=fopen($file,'a');
fwrite($f,"Query String:".$_SERVER['QUERY_STRING']."\n");
fclose($f);

It never returns anything. I'm simply trying to record the queried url when someone visits (i.e. http://example.com/index.php?q=string. Other $_SERVER fields seem to work just fine, it only seems to be the query string that doesn't work. Maybe there's something I need to setup in my .htaccess?

I'm hoping someone has an answer to how to get this to information to show.

9
  • 1
    replace $_SERVER with $_REQUEST or $_GET Commented Jan 1, 2013 at 8:25
  • 1
    Try looking at the result of echo '<pre>' . print_r($_SERVER, true) . '</pre>'; and verify that QUERY_STRING is there. Commented Jan 1, 2013 at 8:27
  • @alfasin, tried both - still no results. Commented Jan 1, 2013 at 8:33
  • @Supericy, that does return the query_string. so the question is why does my code above not? thanks Commented Jan 1, 2013 at 8:34
  • yep, it exists and writes other .$_SERVER information in there just fine. Commented Jan 1, 2013 at 8:38

1 Answer 1

1

This solved the problem:

$_SERVER['REDIRECT_QUERY_STRING']

solution from https://stackoverflow.com/a/11618256/1125006

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.