Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

switch case if cookie is set

     
8:17 pm on Dec 14, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2008
posts: 94
votes: 0


im trying to see if a cookie is set with switch/case.


switch(TRUE) {
case (!isset($_COOKIE[$name])):
header("Location: 1.php");
break;
case (isset($_COOKIE[$name])):
header("Location: 2.php");
break;
}

its not working, so i dont know what to do. any suggestions?

11:10 pm on Dec 14, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Oct 3, 2007
posts:61
votes: 0


I generally wouldn't use a switch for less than 3 options, but if you want to do that, I think you should ask the question (is it set) in the switch, and then the answer to the question is the case.

switch(isset($_COOKIE[$name])): ) {
case (TRUE):
header("Location: 1.php");
break;
case (FALSE):
header("Location: 2.php");
break;
}

Hope that helps.

Jon

11:19 pm on Dec 14, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2008
posts:94
votes: 0


hmm, im still getting a blank white screen. no error as far as i can see except you did add an extra ")" in the switch statement after the ":"
1:48 pm on Dec 15, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


Always exit after a redirect header.
header("Location: $newResource"); 
exit;

Also, it is best practice to build a full url in the new resource, including schema (http part), domain, and path to resource. HTTP/1.1 requires an absolute URI. Notes explaining how to do so can be found on the PHP header [php.net] manual page.