2017-07-07 200 views
0

顯示回顯後,當您點擊'確定',它只是去顯示什麼都不顯示(所以我結束了一個空白屏幕)的PHP文件,這發生了兩次,我該如何修復它?Php後顯示空白屏幕回顯

在顯示第二個回顯後,當您點擊'ok'時,它必須返回到頁面以便用戶可以執行reCAPTCHA,現在它只進入不顯示任何內容的php文件(所以我最終一個空白屏幕)

<?php 
// grab recaptcha library 
require_once "recaptchalib.php"; 

// your secret key 
$secret = "secretkey"; 

// empty response 
$response = null; 

// check secret key 
$reCaptcha = new ReCaptcha($secret); 

// if submitted check response 
if ($_POST["g-recaptcha-response"]) { 
$response = $reCaptcha->verifyResponse(
    $_SERVER["REMOTE_ADDR"], 
    $_POST["g-recaptcha-response"] 
); 
} 

if ($response != null && $response->success) { 
if(isset($_POST['submit'])) { 
$to = "[email protected]"; 
$subject = "Voorstel ---.synology.me"; 
$suggest = $_POST['comment']; 

$body = " NL\n Suggestie: $suggest\n"; 

echo "<script>alert('Je voorstel is verstuurd, wij proberen dit zo snel mogelijk te verwezelijken!');</script>"; 
//after previous echo is displayed, when you click 'ok', it just goes to the php file which displays nothing (so I end up with a blank screen) 
$headers = "From: [email protected]" . "\r\n"; 
mail($to, $subject, $body, $headers); 
} else { 
echo "Er ging iets mis, probeer opnieuw of contacteer de administrator op [email protected]!"; 
} 

} else { 
echo "<script>alert('Vul de Captcha correct in!');</script>"; 
//after previous echo is displayed, when you click 'ok', it must go back to the page so the user can do the reCAPTCHA 
//now it just goes to the php file which displays nothing (so I end up with a blank screen) 
} 
?> 
+3

不共享你的私鑰公開 –

+1

打開使用error_reporting,看它是否顯示了一個致命的錯誤 – ThisGuyHasTwoThumbs

+0

在你過去的其他語句的頁面加載完成後,你給用戶一個JavaScript警告,在用戶點擊後'確定'肯定沒有發生,因爲頁面完成加載。 – Harrie

回答

2

而不是一個警報,如何確認重定向頁面?

<script> 
if(confirm('Vul de Captcha correct in!')){ 
    window.location.href = "yourpage.php"; 
} 
</script> 

不要忘記確保你的回聲格式正確。

echo "<script> 
    if(confirm('Vul de Captcha correct in!')){ 
     window.location.href = 'yourpage.php'; 
    } 
</script>"; 

無論選擇何種方式,只要用if語句就可以產生相同的效果。

<script> 
    if(confirm('Vul de Captcha correct in!')){ 
     window.location.href = "yourpage.php"; 
    }else{ 
     window.location.href = "yourpage.php"; 
    } 
</script> 
+0

解析錯誤:語法錯誤,意外的'yourpage'(T_STRING),期待','或';'在/volume1/web/JocanasNLsuggest.php上線42 它給了我這個錯誤。如果我用https://google.com/替換yourpage.php,我仍然會得到相同的錯誤。難道我做錯了什麼? – Limoentaart

+0

您必須刪除nextline。將所有代碼包裝在一行中。 – Th3

+0

謝謝,它現在可以工作!當我按ok,頁面重新加載,但當我按下取消,它結束了PHP,我最終再次白色屏幕。我怎麼能這樣做,當你按下取消,它確實一樣。或者有沒有可能讓取消按鈕消失? – Limoentaart