homepage Welcome to WebmasterWorld Guest from 54.161.247.22
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
switch case if cookie is set
tr8er8




msg:3807374
 8:17 pm on Dec 14, 2008 (gmt 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?

 

jbroder




msg:3807488
 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




msg:3807495
 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




msg:3807811
 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved