Jump to content

Make PHP issue an HTTP request with POST form data - seperate from the user


10legit10quit

Recommended Posts

One PHP file (execute.php) needs to be sent a POST variable to function. Another PHP file (interface.php) provides the user interface for the program. Interface.php needs to communicate with execute.php by making an HTTP request, that includes a POST variable. However, this variable should NOT be accessible to the end user.

 

What should happen is:

User loads interface.php

Hits a button, POST variable is sent to execute.php without the user being able to see it

Execute.php returns content to user, or to interface.php

 

The two scripts cannot be integrated, what is needed is a way to query one (execute.php) with a hidden POST variable, without leaking that variable to the user. Is this possible?

Yay Google, think I found what was needed:

 

From http://netevil.org/blog/2006/nov/http-post-from-php-without-curl

"here's an example of how to send a POST request with straight up PHP, no cURL:"

 

<?php

 

$postdata = http_build_query(

    array(

        'var1' => 'some content',

        'var2' => 'doh'

    )

);

 

$opts = array('http' =>

    array(

        'method'  => 'POST',

        'header'  => 'Content-type: application/x-www-form-urlencoded',

        'content' => $postdata

    )

);

 

$context  = stream_context_create($opts);

 

$result = file_get_contents('http://example.com/submit.php', false, $context);

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.