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?
jbroder
11:10 pm on Dec 14, 2008 (gmt 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
tr8er8
11:19 pm on Dec 14, 2008 (gmt 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 ":"
coopster
1:48 pm on Dec 15, 2008 (gmt 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.