I have searched everywhere for an answer and the ones I find don't seem tyo work on my server. I had to get a TomCat server so I could host and run an RPG game. Within the game, players are given a Coupon code for use on the website, externally from the game. By visiting the website and putting their 6 digit code into the form, they recieve a printable coupon. Still with me?
I tried creating a process.php file that would take the text input from my form and redirect the user to the appropriate page.
The form sends only 1 variable called "code".
I basically need a script that will take "code", match it up with a URL.
I though maybe the following would work but I can't seem to get the syntax correct.
(Below is the basic structure I've been trying to acheive with no success)
essentially,
if (code=111111)
redirect (page1.htm)
elseif (code=000000)
redirect (page2.htm)
else invalid code
I need this to be scalable, so I can add unlimited codes redirecting to predefined URLs. Any thoughts, suggestions or code snippets would be extremely helpful. I don't have a big budget so I have to work this out. But I am more than willing to give anyone that helps me, a listing as a Game Contributor with a link to their website and free site & game access for life.
Kevin Loring
Conditional redirect from user text input
Started by DunedinRPG, May 09 2006 02:12 PM
7 replies to this topic
#1
Posted 09 May 2006 - 02:12 PM
#2
Posted 09 May 2006 - 04:32 PM
is this what your looking for?
<?php
if($code == 125365){
header("Location: page1.php");
}elseif($code == 434344){
header("Location: page2.php");
}elseif($code == 987546){
header("Location: page3.php");
}else{
echo 'Nice try dude :)'
}
?>
#3
Posted 09 May 2006 - 04:37 PM
Avalanche: couldn't that be written as a switch/case too?
<?php
switch ($code) {
case "125365": header("Location: page1.php"); break;
case "434344": header("Location: page2.php"); break;
case "987546": header("Location: page3.php"); break;
default: echo 'Nice try dude :)'; break;
}
?>
Edited by SpaceGhost, 09 May 2006 - 04:53 PM.
#4
Posted 10 May 2006 - 02:36 AM
yup, that would probably do the job aswell, along with a 1000 other ways
^^
#5
Posted 10 May 2006 - 09:00 AM
You guys rock, I've been reading php 5 manual but it only gives generalized ideas of how the code goes together no actual examples. You both will be listed on my website as contributors. Thank you.
Please send me some info you would like posted about you in the game contributors section.
Name, occupation, url, email whatever. I will see to it that it is posted immediately.
Corporate at mypcdreams.com
Please send me some info you would like posted about you in the game contributors section.
Name, occupation, url, email whatever. I will see to it that it is posted immediately.
Corporate at mypcdreams.com
#6
Posted 10 May 2006 - 02:05 PM
its cool for now, i might actually get back to you when i have my site finished, which may take quite a while
#7
Posted 10 May 2006 - 02:15 PM
I think the following would do good too, because every time you just have to add one small line.
I guess that works. It's the way I would have done it *(but ofcourse I could be wrong). Every time you want to add a page, all you have to do is create a new item in the $urls array, similar to the first three lines.
$urls["125365"] = "page1.php";
$urls["434344"] = "page2.php";
$urls["987546"] = "page3.php";
if(isset($urls[$code])) {
header("Location: ".$urls[$code]);
} else {
echo "so man, this is a no-go.";
}
I guess that works. It's the way I would have done it *(but ofcourse I could be wrong). Every time you want to add a page, all you have to do is create a new item in the $urls array, similar to the first three lines.
Edited by Wybe, 10 May 2006 - 02:16 PM.
#8
Posted 13 May 2006 - 04:25 PM
Man that script was great stuff. Please feel free to email me when your site is finished or when you are ready and I'll be sure to post both of you as contributors.
Again, thanks so much!
admin@dunedinrpg.com
Again, thanks so much!
admin@dunedinrpg.com
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
