Re: redirecting with variables *depending* on a variable
| From: | Steve Keller | Date: | Wed, 30 Apr 2003 21:01:30 +0000 |
| Subject: | Re: redirecting with variables *depending* on a variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145860@lists.php.net to get a copy of this message | ||
At 4/30/2003 10:11 PM, Ryan A wrote:
Is there any way I can do this: if($product_id=1) {send to php script that handles id 1 (script1.php)} else if($product_id=2) {send to php script that handles id 2 (script2.php)} ....etcOk, this is just off the top of my head and assumes A. that your variables are coming from a POST, B. you're sending your variables to the next page via POST, and C. your users can use basic javascript. If those assumptions aren't correct, then the changes, except for the last one, are minor. <!-- script1, script2, etc. --> <form name="myForm" method="post" action="script<? echo $product_id; ?>.php"> <!-- For each variable, create a hidden form variable --> <? foreach ($HTTP_POST_VARS as $key => $value) { ?> <input type="hidden" name="<? echo $key; ?>" value="<? echo $value; ?>"> <? } ?> </form> <!-- submit the form to the next page --> <script> document.myForm.submit(); </script> If this doesn't work for you, you can also use cURL to send the data directly from PHP. Or, if you want to use the GET method, you could try creating a location header: $thisLocation = "Location: script".$product_id.".php?thisVariable=".$thisVariable."&thatVariable=".$thatVariable; header ($thisLocation); But then you have to write out all your variable names by hand. Hope this helps at least a little. ~Steve-o -- S. Keller UI Engineer The Health TV Channel, Inc. (a non - profit organization) 3820 Lake Otis Pkwy. Anchorage, AK 99508 907.770.6200 ext.220 907.336.6205 (fax) Email: skeller@healthtvchannel.org Web: www.healthtvchannel.org