开发者

PHP listener script that can read incoming $_REQUEST or $_POST variables

I am trying to write a PHP script that listens for incoming $_REQUEST or $_POST variables that are sent by a web application as part of a 2-way communication.

HTTP GET calls will be made to the web app in format similar to this.

The WEBAPP will then send a POST response to my listener script (http://TRAVISNG.com/listener.php) and so I was wondering if my php script could parse it without me executing the php script manually?

Note that I am not referring to writing a script that listens for network requests on a socket.开发者_如何学编程

Basically, I want to parse the POST data sent by the web app and write it out to a log file. Therefore, every time I run my listener script it will read the log file and print out all the POST responses sent to my listener script.

Here's some of the code that I've written:

<?php

    // Read incoming POST request
    if (!empty($_POST)){
        $params = join(" ", $_POST);
        //print_r($params);
        echo "|$params|";
    }

    // Print params & timestamp to file called listenerLog.txt
    $logFile = "http://travisng.com/listenerLog.txt";

    $fileHandle = fopen($logFile, 'a') or die("Unable to open the listenerLog.txt.");
    fwrite($fileHandle, $params);
    fclose($fileHandle);

    $output = file_get_contents($logFile);

    // Print listenerLog.txt
    //echo $output;

?>

Cheers,

Travis


To overcome this issue, I decided to create a CGI listener script and process REQUEST parameters from there. The CGI script was invoked whenever a GET/POST request came through and the requests were written out to a log file.


Based on your example call/url they will be in the $_GET global.

So try:

// Read incoming POST request
if (!empty($_GET)){
    $params = join(" ", $_GET);
    //print_r($params);
    echo "|$params|";
}

You could use $_REQUEST - this will contain items $_GET and $_POST and (depending on version or php.ini config $_COOKIE too).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜