Jump to content

Conditional redirecting


Batric

Recommended Posts

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

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

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")
  		};
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.