T2theC Posted April 22, 2009 Share Posted April 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted April 22, 2009 Share Posted April 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
tefuzz Posted April 22, 2009 Share Posted April 22, 2009 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; } Quote Link to comment Share on other sites More sharing options...
T2theC Posted April 22, 2009 Author Share Posted April 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
tefuzz Posted April 22, 2009 Share Posted April 22, 2009 I'm a newbie too, i had asked a similar question to this, and got lots of advice. I decided to go with the switch(). just seemed cleaner, and easier to manage than a bunch of IF statements. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted April 22, 2009 Share Posted April 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 22, 2009 Share Posted April 22, 2009 If you've got one or two different outcomes then an if() statement is fine. Any more than that and I'd use switch() instead. Don't forget about the default clause! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 22, 2009 Share Posted April 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted April 22, 2009 Share Posted April 22, 2009 True you are correct. I had defaulted to my own behaviors. But that is why I declare which array I am working with so that I do not confuse it with other values I may have already created as can happen when using $_REQUEST. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.