I need somebody to help me to capture the http post coming to a PHP script. For example I will host this script at my website : http: //mydom.com/http_analyser.php When I post a data like this http: //mydom.com/http_analyser.php?u...this+is+a+test I want to log this data to a log / txt file.
Try this, should work <?php $query = $_SERVER['QUERY_STRING']; // gets the query string info $fp = fopen("querystrings.txt", "a"); // opens the file and appends flock($fp, LOCK_EX); // lock the file fwrite($fp, $query."\r\n"); // write to the file flock($fp, LOCK_UN); // unlock the lock fclose($fp); // close the file ?> PHP:
Great, can you please tell me how to include the URL to the log file too? When I tried your script it is logging the query eg: username=jone&password=pass&subj=Testing HTML: How can I log the URL of the incoming POST too like: http://mydom.com/script.php?username=jone&password=pass&subj=Testing HTML:
I think this is what you want, test it and let me know. <?php $query = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $fp = fopen("querystrings.txt", "a"); // opens the file and appends flock($fp, LOCK_EX); // lock the file fwrite($fp, $query."\r\n"); // write to the file flock($fp, LOCK_UN); // unlock the lock fclose($fp); // close the file ?> PHP: