switch redirect problem

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
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

switch redirect problem

Post by speedamp »

hello everybody,

i have this script, and i cannot get this to pass to the correct page. It only goes to ELSE section of the statement:

Any ideas why it won't forward correctly?

target page:
---------------------------------------------------------------------------------
<?
if (isset($_GET['page']) && $_GET['page'] != '') {

Switch ($_GET['page']) {
Case "corporate":
$url = "corporatepage";
break;

Case "usatf":
$url = "usatfpage";
Break;

Case "school":
$url = "schoopage";
Break;

Case "volunteer":
$url = "volunteerpage";
Break;

Case "youth":
$url = "youthpage";
Break;

}

Header('Location: ' . $url);

}

else {

$url = "........page that is always fowarded to";
Header('Location: ' . $url);

}

?>


-----------------------------------------------------------------------

this always goes to the ELSE page.

thanks,
-Michael
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first, before a mod slaps you read this

looks like $_GET['page'] either isn't set properly or is empty.. can you post the code that leads into this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

a better way to check it its set or empty is

Code: Select all

<?php
if (!empty($_GET['page'])) {
?>
empty checks to see if it is even set, if not the statement fail and it also checks to see if the value of NULL, and if so it will fail .. because we have made the empty inversed.

Try echo'ing your variables to see if they are being set.

ie echo $_GET['page']; at the bottom of your page.
Post Reply