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?

Link to comment
Share on other sites

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);

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.