Jump to content

Setting/Reading cookies


Thomisback

Recommended Posts

Hey,

 

I am trying to set & read a cookie but the problem is that I am trying to do this in a

if($_GET['page'] == "loggedin"){

page, at the top I include the header and then the cookie gives me the error that the header have already been sent.

 

I have tried

ob flush

without luck, still does not work.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/101189-settingreading-cookies/
Share on other sites

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="nl" />
<title>title</title>
<link href="stijl.css" type="text/css" rel="stylesheet" />
<script src="js.js" type="text/javascript" language="javascript"></script>
</head>

I use something like this:

 

if(isset($_COOKIE['cookie_inf'])) {
$cooky = $_COOKIE['cookie_inf'];
if($cooky != 'thepassword') {
	header("Location: index.php");
}
} else {
	header("Location: index.php");
}

 

And it needs to be BEFORE any HTML is written.

 

Also, you might not want to use a GET method for something like "loggedin".

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.