Welcome to WebmasterWorld Guest from 107.20.110.201

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

switch case if cookie is set

     

tr8er8

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

5+ Year Member



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)

5+ Year Member



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)

5+ Year Member



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)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month