Jump to content

[SOLVED] Cookie setting troubles


mikwit

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/169382-solved-cookie-setting-troubles/
Share on other sites

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.