...

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



Morgoth
11-21-2003, 10:18 PM
Hello,

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.

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



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


Thanks to a friendly soul.

missing-score
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:

---------------------------------------------------
var1=value1&var2=value2&var3=value3
var4=value4&var5=value5&var6=value6
var7=value7&var8=value8&var9=value9
---------------------------------------------------

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");

with

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





<?php

$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
?>

missing-score
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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum