mikwit Posted August 8, 2009 Share Posted August 8, 2009 I've been trying to get a smooth way to set cookies and for some reason its not working... I know the function is getting called (I put an echo "hello"; command in the function to check) but for some reason that I don't know the cookie isn't getting set... I have other cookies on the site that are working so i'm not blocking them and using a web dev toolbar there are no cookies from this command. Main file, Liked to as index.php?id=1 <html> <head> <link rel="stylesheet" type="text/css" href="./include/css.css"> <script type='text/javascript' src='./include/jquery.pack.js'></script> <script type='text/javascript' src='./include/custom.js'></script> <?php include("./include/functions.php"); ?> </head> <body> <?php if($_GET['id'] != ""){ setSchoolid($_GET['id']); echo "hello"; } getSchoolid(); ?> </body> </html> And then there's the included function file which I'll just show the important parts: function getSchoolid(){ if(isset($_COOKIE['schoolid'])){ // cookie exists! do this: include("./index_body.php"); }else{ include("./index_get.php"); } } function setSchoolid($id){ setcookie ('schoolid', "1", time()+(60*60*24)); echo "hello"; } Any help would be greatly appreciated, thanks a bunch. So When i go to index.php?id=1 I get "hellohello" but without the set cookie. Quote Link to comment https://forums.phpfreaks.com/topic/169382-solved-cookie-setting-troubles/ Share on other sites More sharing options...
Mark Baker Posted August 8, 2009 Share Posted August 8, 2009 Cookies have to be set before any output is sent to the browser Quote Link to comment https://forums.phpfreaks.com/topic/169382-solved-cookie-setting-troubles/#findComment-893738 Share on other sites More sharing options...
mikwit Posted August 8, 2009 Author Share Posted August 8, 2009 Woops, thats a ton, moved it up to above the <html> and it works now. Quote Link to comment https://forums.phpfreaks.com/topic/169382-solved-cookie-setting-troubles/#findComment-893741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.