forms - PHP if statement not working as expected with filter_var -


i have form posts variables through php processing script.

before processing script begins sanitize posted variables:

$contact_name = filter_var($_post['contactname'], filter_sanitize_string); $company = filter_var($_post['company'], filter_sanitize_string); $telephone = filter_var($_post['telephone'],filter_sanitize_number_int); 

so far. good.

but sanitizing , validating email real pain.

$email = $_post['email']; $sanitised_email = filter_var($email, filter_sanitize_email); $email_is_valid = filter_var($email, filter_validate_email); 

if $sanitised_email isn't same $email, want go form page:

if ($sanitised_email != $email) { header('location: http://'.$_server['http_host'].'/form.php'); } 

if $email_is_valid false, want go form page:

if ($email_is_valid == false) { header('location: http://'.$_server['http_host'].'/form.php'); } 

neither of these 2 if statements work when enter email both invalid , in need of sanitisation such as:

i.am.(totally)invalid@asanemailaddress 

what doing wrong? have messed syntax somewhere?

syntax seems good. think problem not ending script after setting header. change to:

if (condition) {         header('location: www.example.com');         exit(); } 

learn how debug code, can echo know if entering structure or not. practice create function redirect pages, it's quick, clean , save lines:

function redirect($page){         header('location: http://'.$_server['http_host']."/$page.php");         exit(); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -