January 14th, 2000, 09:01 AM
I need to redirect to a specific PHP file depending on the content of a variable, for example, in case the variable $action has a 1 then go to page add.php3, 2 then redirect to page modify.php3, etc. How could I go about doing this? Thanks in advance
January 14th, 2000, 09:16 AM
You can use the header("Location: url"); to redirect, as long as you do it before sending anything to the output stream (i.e. HTML or print/echo).
If you only have a couple of possibilities for the redirect location I'd just use an if:
header ("Location: modify.php3");
If you have a few to several pages you could use a switch/case construct.
But, if you have several values for $action, I'd use an array. You could set the array up in an included file for ease of editing.
// begin actionarray.php3
Then in the main script (perhaps you want to check to see if $action is set first):
//do something else