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
Share on other sites

Yes this will work but your use of $_REQUEST is actually the $_GET variable that will be appended to the url hyperlink with in the email.

Just make sure that your hyperlink includes this: "?code=CODE_1" at the end, or which ever code they are assigned.

Link to comment
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;

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

    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.

Link to comment
Share on other sites

    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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.