View Full Version : Request: Print QueryString into text file.

11-21-2003, 10:18 PM

I am wondering if anyone here, that knows php, would be able to write up some code that will take an entire QueryString and print it into a text file for me?

I don't know PHP, but I need this little script. I know how to do this in ASP, but I can't use ASP for this.

Thank you for your help.

11-21-2003, 10:55 PM
I have the code now.

$fp = fopen("logfile.txt", "a");
fputs($fp, $_SERVER["QUERY_STRING"]);

Thanks to a friendly soul.

11-21-2003, 11:04 PM
You will need to ensure that the file is CHMOD to 777.

The example below will add the querystring into the textfile, after the previous one. So creating a textfile like:


where each new line is written when the script is run. If you want the old information in the file to be overwritten with the new query string, then replace this line:

$fp = fopen("querystrings.txt", "a");


$fp = fopen("querystrings.txt", "w");


$query_string = $_SERVER['QUERY_STRING']; // gets the query string info

$fp = fopen("querystrings.txt", "a"); // opens the file to ammend (add to)
// as i mentioned above, replace "a" with "w" to overwrite the old data

flock($fp, LOCK_EX); // lock the file to avoid other executions trying to write to it at once (can corrupt otherwise)

$fp = fputs($query_string, $fp); // write the file information

flock($fp, LOCK_UN); // unlock the set lock above

fclose($fp); // close the file handle

11-21-2003, 11:05 PM
i see someone else got in there first

however, you should use the flock() command i used, to avoid corruption.

11-21-2003, 11:39 PM
Thanks everyone. I am glad you added your input.