0

Possible Duplicate:
Redirect with POST data

Is it possible for a script to redirect to a URL with a POST request in PHP?

The code I currently have uses javascript to submit a form when the body of the page has loaded. I want to avoid this and use a more robust solution if it is possible.

The current code looks like this:

<?php
// Change this secret key so it matches the one in the imagemanager/filemanager config
$secretKey = "someSecretKey";

// Check here if the user is logged in or not

if (!isset($_SESSION["some_session"]))
    die("You are not logged in.");


// Override any config values here
$config = array();
//$config['filesystem.path'] = 'c:/Inetpub/wwwroot/somepath';
//$config['filesystem.rootpath'] = 'c:/Inetpub/wwwroot/somepath';
// Generates a unique key of the config values with the secret key
$key = md5(implode('', array_values($config)) . $secretKey);
?>

<html>
    <body onload="document.forms[0].submit();">
        <form method="post" action="<?php echo htmlentities($_GET['return_url']); ?>">
            <input type="hidden" name="key" value="<?php echo htmlentities($key); ?>" />
            <?php
            foreach($config as $key => $value) {
                echo '<input type="hidden" name="' . 
                          htmlentities(str_replace('.', '__', $key)) . '" 
                          value="' . htmlentities($value) . '" />';
            }
            ?>
        </form>
    </body>
</html>

Which is an example from the MCImageManager and MCFileManager file package.

Echoing out the response from a curl request will not work in this instance due to the use of relative file paths in the HTML, which I am unable to easily change.

Community
  • 1
  • 1
Treffynnon
  • 21,365
  • 6
  • 65
  • 98
  • possible duplicate of [Redirect with POST data](http://stackoverflow.com/questions/6614076/redirect-with-post-data) and [PHP Redirect with POST data](http://stackoverflow.com/questions/5576619/php-redirect-with-post-data) – deceze Aug 04 '11 at 13:55
  • @deceze agreed - voting to close. I didn't see those ones in my searching. – Treffynnon Aug 04 '11 at 13:58

1 Answers1

1

No, this is not possible.

You have to use Javascript to submit a form or do an AJAX POST.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175