perezf Posted September 11, 2006 Share Posted September 11, 2006 i made a script now from scratcha user login/registeri cant figure out why the users cant see the secret pagesmaybe i made a mistake but when they click on a secret page links it loads them back to the login pagebelow is a piece of the check login code[code]if($num !=0) { $cookie_name = "auth"; $cookie_value = "ok"; $cookie_expire = "0"; $cookie_domain = $_SERVER['PHP_SELF']; setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0); $display_block = " <p><strong>Secret Menu:</strong></p> <ul> <li><a href=\"secretA.php\">secret page A</a> <li><a href=\"secretB.php\">secret page B</a> </ul>"; } else { header("Location: /show_login.html"); exit; }[/code]and here is the code that checks if the user can see the page "secretA.php"[code]<?phpif($COOKIE[auth] == "ok") { $msg = "<p>Welcome to secret page A, authorized user!</p>"; } else { header("Location: show_login.html"); exit; }?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Secret Page A</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php echo "$msg"; ?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/ Share on other sites More sharing options...
ober Posted September 11, 2006 Share Posted September 11, 2006 DO NOT POST THREAD TITLES IN ALL CAPS! Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90051 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 ok Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90053 Share on other sites More sharing options...
corbin Posted September 11, 2006 Share Posted September 11, 2006 try $COOKIE['auth'] Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90054 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 still didnt work ??? Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90056 Share on other sites More sharing options...
corbin Posted September 11, 2006 Share Posted September 11, 2006 $_COOKIE['auth'] and if that doesnt work try double quotes Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90058 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 both ways did not work i am so confused Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90061 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 anyone have any more ideas ??? Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90065 Share on other sites More sharing options...
HuggieBear Posted September 11, 2006 Share Posted September 11, 2006 Are you certain you have it correct...You missed out the parts I've included in [color=red]red[/color] below[b]$[color=red]_[/color]COOKIE[[color=red]'[/color]auth[color=red]'[/color]][/b]Both the underscore, and the single quotes should be there.Also when setting the expire, try without the quotes... [code=php:0]$cookie_expire = 0;[/code]RegardsRich Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90066 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 here is the new code but it is still not working[code]<?phpif($_COOKIE['auth'] == "ok") { $msg = "<p>Welcome to secret page A, authorized user!</p>"; } else { header("Location: show_login.html"); exit; }?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Secret Page A</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php echo "$msg"; ?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90068 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 I think i found where the problem is happening because i looked through my cookies and nothing was there[code] $cookie_name = "auth"; $cookie_value = "ok"; $cookie_expire = "0"; $cookie_domain = $_SERVER['PHP_SELF']; setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0); [/code] Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90071 Share on other sites More sharing options...
HuggieBear Posted September 11, 2006 Share Posted September 11, 2006 ok, lets look back at the original code....a) Have you tried to echo $num to make sure it's not equal to zero, as this is a condition of you setting the cookie?b) Have you tried to echo $_SERVER['PHP_SELF'] to see if you get the expected result?I'd bet the problem is option b)... Try just putting your domain in there $cookie_domain = "mydomain.com" as $_SERVER['PHP_SELF'] gives the path and filename, not the domain.RegardsRich Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90072 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 [quote author=HuggieBear link=topic=107694.msg432370#msg432370 date=1158015307]ok, lets look back at the original code....a) Have you tried to echo $num to make sure it's not equal to zero, as this is a condition of you setting the cookie?b) Have you tried to echo $_SERVER['PHP_SELF'] to see if you get the expected result?I'd bet the problem is option b)... Try just putting your domain in there $cookie_domain = "mydomain.com"RegardsRich[/quote]this was the problem thank you "$_SERVER['PHP_SELF']" Link to comment https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.