私はPHPで処理しているフォーム提出に入力されたデータを検証しようとしています。まず、フィールドが埋め込まれていることを確認した後、何らかの理由ですべてが無視されているように見え、データは私が何をしようとしてもDBに提出されています。フォームのバックエンド検証が無視されます
// example of validation (this is just duplicated for 4 fields)
if (isset($_POST["fullname"]) && !empty($_POST["fullname"])) {
header('Location: http://mywebsite.com/error');
} else {
// Trying to get it to redirect at all
header('Location: http://mywebsite.com/error');
}
$email = $_POST['email'];
// using google code email validation
include('EmailAddressValidator.php');
$validator = new EmailAddressValidator;
if ($validator->check_email_address($email)) {
// Email address is technically valid
} else {
header('Location: http://mywebsite.com/error');
}
// If this line is reached, submit the data to the DB but there's no way this line should be reached because the very first if & else statement should send it to the error page.
ご協力いただければ幸いです。この時点でこれを数時間修正しようとしていました。下の例を参照してくださいheader.pleaseにリダイレクトした後exit;
を追加
ヘッダーでリダイレクトしてもプロセスが停止するわけではなく、単にヘッダーを送信し、プロセスを終了させる場合は 'exit();'を追加してください。 –
'isset'と'!empty'は必要ありません。 '!empty'で十分です。 – chris85
@JonStirlingが指を置いています。 header()文は実行を停止しません。あなたのコードは、直前のheader()を実行し続けます。 header()の後で実行を止めたい場合は、そこで停止させる必要があります。 –