Getting http post values



<?php

//functions.php

function PostRequest($url, $referer, $_data) {

 

    // convert variables array to string:

    $data = array();    

    while(list($n,$v) = each($_data)){

        $data[] = "$n=$v";

    }    

    $data = implode('&', $data);

    // format --> test1=a&test2=b etc.

 

    // parse the given URL

    $url = parse_url($url);

    if ($url['scheme'] != 'http') { 

        die('Only HTTP request are supported !');

    }

 

    // extract host and path:

    $host = $url['host'];

    $path = $url['path'];

 

    // open a socket connection on port 80

    $fp = fsockopen($host, 80);

 

    // send the request headers:

    fputs($fp, "POST $path HTTP/1.1\\r\
");

    fputs($fp, "Host: $host\\r\
");

    fputs($fp, "Referer: $referer\\r\
");

    fputs($fp, "Content-type: application/x-www-form-urlencoded\\r\
");

    fputs($fp, "Content-length: ". strlen($data) ."\\r\
");

    fputs($fp, "Connection: close\\r\
\\r\
");

    fputs($fp, $data);

 

    $result = ''; 

    while(!feof($fp)) {

        // receive the results of the request

        $result .= fgets($fp, 128);

    }

 

    // close the socket connection:

    fclose($fp);

 

    // split the result header from the content

    $result = explode("\\r\
\\r\
", $result, 2);

 

    $header = isset($result[0]) ? $result[0] : '';

    $content = isset($result[1]) ? $result[1] : '';

 

    // return as array:

    return array($header, $content);

}

 

// submit these variables to the server:

$data = array(

    'param1' => '1',

    'param2' => '2',

    'param3' => '3'

);

 


list($header, $content) = PostRequest(

    "http://localhost/examples/example.php",

    "http://localhost/examples/example.php",

    $data

);



 

// print the result of the whole request:

//print $content;

 

//print $header; //--> prints the headers



?>


when i uncomment print $content;, and open it in a broswer i am getting the values of param1, param2, param3


http://localhost/examples/example.php
print_r($_REQUEST);

when i open http://localhost/examples/example.php i am getting blank array()

I have to get those values in example.php, should i have to run command prompt, please tell me the procedure.

Thanks

How do you “open” it? Using a web browser to navigate to the url?

$post = $_POST;

Still i am not able to figure it out.

How do you “open” it? Using a web browser to navigate to the url?

Yes, http://localhost/examples/example.php

$post = $_POST;

where i have to change?