重複の可能性:
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>
これは、MCImageManagerおよびMCFileManagerファイル パッケージの例です。
この例では、HTML で相対ファイル パスが使用されているため、 curl 要求からの応答をエコーアウトすることはできません。これは簡単には変更できません。