if statement return a new php page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ringartdesign
Forum Newbie
Posts: 21
Joined: Wed Sep 10, 2008 10:11 am

if statement return a new php page?

Post by ringartdesign »

i have this if statement that returns a quote based on user input in an html form:

if (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="male"))
$quote=31.44;
elseif (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="female"))
$quote=44.65;
elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="male"))
$quote=35.91;

is there a way to redirect someone to a different php page if they enter an age 65-80?

Thanks!
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: if statement return a new php page?

Post by aceconcepts »

oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: if statement return a new php page?

Post by oscardog »

Code: Select all

 
header("location: WHERE_YOU_WANT_THEM_TO_GO.php");
 
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: if statement return a new php page?

Post by novice4eva »

The one and only problem with header is that it returns error in case you have anything echoed before it, even a space would. I like header if it didn't have that short come, so again there is javascript solution: but who knows who have their javascript disabled!! Hopefully if they are not, do something like this:

Code: Select all

 
elseif (($_POST['age'] >= 65) && ($_POST['age'] <= 80))
{
echo '<meta HTTP-EQUIV=\"refresh\" content=".$refreshTime.";url=\"".$url."\">';//WHERE $url is the page you want to redirect, $refreshTime is the time by which you delay the redirection, exactly what aceconcepts suggested
/* OR YOU COULD OPEN A NEW PAGE*/
echo '<script>window.open("'.$url.'");</script>';
/* OR YOU COULD OPEN IT IN THE SAME PAGE AS*/
echo '<script>window.location.href="'.$url.'";</script>';
}
 
Post Reply