0

可能重复:
使用 POST 数据重定向

脚本是否可以通过 PHP 中的 POST 请求重定向到 URL?

我目前拥有的代码在页面正文加载时使用 javascript 提交表单。如果可能的话,我想避免这种情况并使用更强大的解决方案。

当前代码如下所示:

<?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>

这是MCImageManagerMCFileManager文件包中的一个示例。

由于在 HTML 中使用了相对文件路径,因此在这种情况下,从curl 请求中回显响应将不起作用,我无法轻松更改。

4

1 回答 1

1

不,这是不可能的。

您必须使用 Javascript 提交表单或执行 AJAX POST。

于 2011-08-04T13:54:52.400 回答