Jump to content

Help with basic IF statement


T2theC

Recommended Posts

Hi guys,

 

I am sending out emails to my database of clients. A client is going to be issued with one of five codes. When they visit my site and enter their code I want them to be taken to a page relating to that code. I am a n00bie so please be gentle...

 

Is this what I need??

$code =  strip_tags ($_REQUEST['code']);

if ($code == 'CODE_1')
      header( "Location: http://www.MYSITE.com/code1" );

elseif ($code == 'CODE_2')
      header( "Location: http://www.MYSITE.com/code2" );

elseif ($code == 'CODE_3')
      header( "Location: http://www.MYSITE.com/code3" );

 

Will this work ok? Is there a better way to do that is SIMPLE and easy for a non coder to understand?

 

Thanks for taking the time out to read this.

Link to comment
https://forums.phpfreaks.com/topic/155171-help-with-basic-if-statement/
Share on other sites

you could also use a switch to accomplish the same goal...my index page is set up this way with multiple variables in the URL to determine what exactly the visitor is doing.

 

but as wolfrage said, your URL would need to be something like http://www.mysite.com/index.php?code=1 (assuming the file you are using is named index.php)

 

here's a quick example...

$code = $_GET['code'];

switch($code) {
  default: 
   include('default.php');
    break;

  case "1":
   include('one.php');
    break;

  case "2":
   include('two.php');
    break;

}

 

Wow, thanks WolfRage for the quick reply.

 

Just to clarify how I want this to work (I'm don't sure I made it clear at the start)...

 

Step 1 = I email my clients with a code

 

Step 2 = They visit my site and enter their code into a form

 

Step 3 = The form posts to the above script

 

Step 4 = The script takes them to a page relating to that code.

 

If this is what you though I said then thats great. Sorry for the newbie-ness. I just want to make sure it will run smoothly. And thanks again for your help, it is really appreciated.

    I recommend you save your clients the trouble of entering the code into a form and just include that code in a hyperlink within the email. But if you use a form then you should recieve the data using the $_POST array. This is just a syntax method that allows for clarity in your code.

    I recommend you save your clients the trouble of entering the code into a form and just include that code in a hyperlink within the email. But if you use a form then you should recieve the data using the $_POST array. This is just a syntax method that allows for clarity in your code.

Depends on the method used in the form declaration.

 

$_REQUEST will pick up both post and get but will also check for cookies amongst other things.

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.