Jump to content

Recommended Posts

i made a script now from scratch
a user login/register
i cant figure out why the users cant see the secret pages

maybe i made a mistake but when they click on a secret page links it loads them back to the login page

below 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]<?php
if($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

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]

Regards
Rich
Link to comment
https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90066
Share on other sites

here is the new code but it is still not working
[code]<?php
if($_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

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

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.

Regards
Rich
Link to comment
https://forums.phpfreaks.com/topic/20434-cookie-help-solved/#findComment-90072
Share on other sites

[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"

Regards
Rich
[/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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.