Batric Posted November 10, 2008 Share Posted November 10, 2008 I have a contact form done in PHP. I want to be sure the users enter the same email address (I have two fields - email and retype email) I tried to do it this way, but it simply won't work: if ( $email == $emailconfirm) { header( "Location: contact.html" ) }; else { header("Location: thankyou.html") }; Any ideas? And how can I check if the user enters valid email address? (with the "@" in the middle) Thanks in any case, Batric Link to comment https://forums.phpfreaks.com/topic/132148-conditional-redirecting/ Share on other sites More sharing options...
gaza165 Posted November 10, 2008 Share Posted November 10, 2008 you need to use regular expressions to validate an email address... http://www.webcheatsheet.com/php/regular_expressions.php this website has a good tutorial on matching email addresses Link to comment https://forums.phpfreaks.com/topic/132148-conditional-redirecting/#findComment-686776 Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 Without seeing the actual form it is hard to say, but it looks like you are assuming register_global is on which is a huge security flaw: if ( $_POST['email'] == $_POST['emailconfirm'] && strstr($_POST['email'], "@")) { header( "Location: contact.html" ); } else { header("Location: thankyou.html"); } The semi-colon should also be after the header line, not after the } To check the at in the middle you would use either www.php.net/ereg or www.php.net/strstr Link to comment https://forums.phpfreaks.com/topic/132148-conditional-redirecting/#findComment-686777 Share on other sites More sharing options...
Batric Posted November 10, 2008 Author Share Posted November 10, 2008 Sorry Here's the entire code: <?php $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $emailconfirm = $_REQUEST['email_confirm'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; if ( $email == $emailconfirm) { header( "Location: thankyou.html" ) }; else { header("Location: contact.html") }; ?> Link to comment https://forums.phpfreaks.com/topic/132148-conditional-redirecting/#findComment-686780 Share on other sites More sharing options...
mattisthenation Posted November 10, 2008 Share Posted November 10, 2008 the first thing would be to take out the semi-colons after the if { } and else { } and put them after the header( ); lines Link to comment https://forums.phpfreaks.com/topic/132148-conditional-redirecting/#findComment-686784 Share on other sites More sharing options...
Batric Posted November 10, 2008 Author Share Posted November 10, 2008 It works now! Thanks a lot Link to comment https://forums.phpfreaks.com/topic/132148-conditional-redirecting/#findComment-686795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.