Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post

    Request: Print QueryString into text file.

    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.

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    I have the code now.

    Code:
    <?
    $fp = fopen("logfile.txt", "a");
    fputs($fp, $_SERVER["QUERY_STRING"]);
    fclose($fp);
    ?>
    Thanks to a friendly soul.

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:

    <?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($fpLOCK_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($fpLOCK_UN); // unlock the set lock above

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

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i see someone else got in there first

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

  • #5
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Thanks everyone. I am glad you added your input.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •