Jump to content


Photo

cookie help-SOLVED


  • Please log in to reply
12 replies to this topic

#1 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:13 PM

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

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;
	}

and here is the code that checks if the user can see the page "secretA.php"
<?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>


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 11 September 2006 - 10:29 PM

DO NOT POST THREAD TITLES IN ALL CAPS!

Info: PHP Manual


#3 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:30 PM

ok

#4 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 11 September 2006 - 10:31 PM

try $COOKIE['auth']
Why doesn't anyone ever say hi, hey, or whad up world?

#5 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:32 PM

still didnt work ???

#6 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 11 September 2006 - 10:36 PM

$_COOKIE['auth'] and if that doesnt work try double quotes
Why doesn't anyone ever say hi, hey, or whad up world?

#7 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:39 PM

both ways did not work i am so confused

#8 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:45 PM

anyone have any more ideas ???

#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 11 September 2006 - 10:46 PM

Are you certain you have it correct...

You missed out the parts I've included in red below

$_COOKIE['auth']

Both the underscore, and the single quotes should be there.

Also when setting the expire, try without the quotes...
$cookie_expire = 0;

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#10 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:51 PM

here is the new code but it is still not working
<?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>


#11 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 10:54 PM

I think i found where the problem is happening because i looked through my cookies and nothing was there
	$cookie_name = "auth";
	$cookie_value = "ok";
	$cookie_expire = "0";
	$cookie_domain = $_SERVER['PHP_SELF'];
	setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0);


#12 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 11 September 2006 - 10:55 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#13 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 11:02 PM

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

this was the problem thank you "$_SERVER['PHP_SELF']"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users