Сегодня я сделал простой регистрационный бланк и работал отлично. Но теперь я понял, что сценарий может быть уязвим для CSRF, поэтому легким решением было добавить API reCaptcha Google. Когда я хотел протестировать скрипт, он показал мне ничего, кроме пустой страницы, хотя у меня не было ошибок.Пустая страница PHP без ошибок
Script
<?php
if($_POST['submit']){
require_once('recaptchalib.php');
$privatekey = "private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
$to = '[email protected]';
$mail_list = $_POST['mail_list'];
$subject = 'New sign up';
$headers = 'From: '. $mail_list .'';
if (!filter_var($mail_list, FILTER_VALIDATE_EMAIL) === false) {
$dodgy_strings = array(
"content-type:"
,"mime-version:"
,"multipart/mixed"
,"bcc:"
);
function is_valid_email($mail_list) {
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~][email protected]([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $mail_list);
}
function contains_bad_str($str_to_test) {
$bad_strings = array(
"content-type:"
,"mime-version:"
,"multipart/mixed"
,"Content-Transfer-Encoding:"
,"bcc:"
,"cc:"
,"to:"
);
foreach($bad_strings as $bad_string) {
if(eregi($bad_string, strtolower($str_to_test))) {
echo "<script>alert('". $bad_string ." found. Suspected injection attempt - mail not being sent.');</script>";
exit;
}
}
}
function contains_newlines($str_to_test) {
if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
echo "<script>alert('newline found in ". $str_to_test .". Suspected injection attempt - mail not being sent.');</script>";
exit;
}
}
if (!is_valid_email($mail_list)) {
echo "<script>alert('Invalid email submitted - mail not being sent.');</script>";
exit;
}
contains_bad_str($mail_list);
contains_bad_str(body);
mail($to, $subject, $mail_list, $headers);
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>List</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form action="" method="post">
<input type="text" name="mail_list" />
<input type="submit" name="submit" value="Sign up" />
<div class="g-recaptcha" data-sitekey="public_key"></div>
<?php
require_once('recaptchalib.php');
$publickey = "public_key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</form>
</body>
</html>
Пожалуйста, обратите внимание, что если есть на самом деле ошибка, что я не заметил, что это потому, что я новичок в PHP, и я использую этот site для обработки ошибок.
С уважением.
'error_reporting (E_ALL); ini_set ('display_errors', '1'); ' – AbraCadaver
пустые страницы. Вызывают (потенциальные) ошибки, и вы не ищете их http://php.net/manual/en/function.error-reporting.php или ваша система не настроена на поиск/запись/отображение. –
белый экран смерти: проверка ошибок \ дисплей выключен, включите их, чтобы увидеть ошибку. в верхней части страницы php добавьте: 'ini_set ('display_errors', 'On'); ini_set ('html_errors', 0); error_reporting (-1); ' –