Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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