現在のリクエストに(307
でリダイレクトして)送信されたフィールドをにリダイレクトすることは可能ですが、人工的に作成するのは難しく、ユーザーがJavaScriptを有効にしているかどうかによって異なります。私はこの関数を使用しますが、ユーザーがjavascriptを無効にしている場合は、その関数に依存しないでください。
<?php
function createHiddenFields($value, $name = NULL)
{
$output = "";
if(is_array($value)) {
foreach($value as $key => $value) {
$output .= self::createHiddenFields($value, is_null($name) ? $key : $name."[$key]");
}
} else {
$output .= sprintf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />",
htmlspecialchars(stripslashes($name)),
htmlspecialchars(stripslashes($value))
);
}
return $output;
}
function redirectNowWithPost($url, array $post_array = NULL)
{
if(is_null($post_array)) { //we want to forward our $_POST fields
header("Location: $url", TRUE, 307);
} elseif(! $post_array) { //we don't have any fields to forward
header("Location: $url", TRUE);
} else { //we have some to forward let's fake a custom post w/ javascript
?>
<form action="<?php echo htmlspecialchars($url); ?>" method="post">
<script type="text/javascript">
//this is a hack so that the submit function doesn't get overridden by a field called "submit"
document.forms[0].___submit___ = document.forms[0].submit;
</script>
<?php print createHiddenFields($post_array); ?>
</form>
<script type="text/javascript">
document.forms[0].___submit___();
</script>
<?php
}
exit();
}
?>
リダイレクトする(出力を書き留めてリダイレクトするのは意味がありません)場合は、出力を書き込まないでください。 –
彼は彼のURLで見える変数を意味します。 – TJHeuvel
CakePHPを使用していますか?そして、あなたが心配しているデータは、URLの 'code = 2345'ですか?この秘密のデータですか? – deceze