Thomisback Posted April 15, 2008 Share Posted April 15, 2008 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 More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 What kind of header are you manually sending? Link to comment https://forums.phpfreaks.com/topic/101189-settingreading-cookies/#findComment-517639 Share on other sites More sharing options...
Thomisback Posted April 15, 2008 Author Share Posted April 15, 2008 <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> Link to comment https://forums.phpfreaks.com/topic/101189-settingreading-cookies/#findComment-517643 Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 right, you can't send any output to the screen before setting cookies (i think) the easiest thing to do is rework the code so the cookie handling happens before that code is outputed Link to comment https://forums.phpfreaks.com/topic/101189-settingreading-cookies/#findComment-517647 Share on other sites More sharing options...
Thomisback Posted April 15, 2008 Author Share Posted April 15, 2008 Allright, thanks i'm going to try it now! Link to comment https://forums.phpfreaks.com/topic/101189-settingreading-cookies/#findComment-517678 Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 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". Link to comment https://forums.phpfreaks.com/topic/101189-settingreading-cookies/#findComment-517694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.