output bufferingを使用すると、ヘッダーが送信された後にのみコンテンツを送信できます。
if(($valid_fname == "Y")&&($valid_sname == "Y")&&($valid_company == "Y")&&($valid_email == "Y")) {
ob_start();
echo "<p class=\"secText\">Thank you for confirming your details, you will be re-directed to \"The Personal Touch\" Whitepaper shortly.</p>\n";
header('Location: http://www.sefasinnovation.co.uk/personal_touch.pdf');
ob_end_flush();
exit();
}
しかし、リダイレクトが行われる前にメッセージを表示する時間が実質的にないので、この方法は役に立たないでしょう。
あなたの最善のアプローチは、特定の時間が経過した後にJavaScriptリダイレクトをトリガーする小さなHTMLページにページをリダイレクトすることです。ここに一般的な考えがあります。詳細を並べ替える必要があります。
PHP notification.html
if(($valid_fname == "Y")&&($valid_sname == "Y")&&($valid_company == "Y")&&($valid_email == "Y")) {
header('Location: http://www.sefasinnovation.co.uk/notification.html');
exit();
// You could also avoid redirection to an HTML file and output the code directly
echo <<<HTML
<html>
<head>
<title>Enter desired title</title>
<script type="text/javascript">
setTimeout(function(){
window.location = "http://www.sefasinnovation.co.uk/personal_touch.pdf";
}, 5000);
</script>
</head>
<body>
<p class="secText">Thank you for confirming your details, you will be re-directed to "The Personal Touch" Whitepaper shortly.</p>
<p>If this page isn't redirected in 5 seconds please click <a href="http://www.sefasinnovation.co.uk/personal_touch.pdf">here</a>.</p>
</body>
</html>
HTML;
}
(上記のPHPコードも出てこのコードを吐くことができますが、前ページの出力がなかった場合のみ)
<html>
<head>
<title>Enter desired title</title>
<script type="text/javascript">
setTimeout(function(){
window.location = "http://www.sefasinnovation.co.uk/personal_touch.pdf";
}, 5000);
</script>
</head>
<body>
<p class="secText">Thank you for confirming your details, you will be re-directed to "The Personal Touch" Whitepaper shortly.</p>
<p>If this page isn't redirected in 5 seconds please click <a href="http://www.sefasinnovation.co.uk/personal_touch.pdf">here</a>.</p>
</body>
</html>
notification.htmlの追加リンクを使用すると、JavaScriptが無効になっている場合に手動でリダイレクトを行うことができます。
ブール値の使い方を教えてください。どうぞ、どうぞ、否定比較の方法を教えてください。 'if(!$ valid_compay)echo 'と入力してください。' 'ははるかに短く読みやすくなりました! – gnur