jesse23 Posted January 30, 2007 Share Posted January 30, 2007 So i have a php code that will set a cookie for my website. the problem is that when i close my browser the cookie dissapears. How would change that? below i have posted the php code.[code]<fieldset><legend>Select School</legend><form action="setcookie.php" method="post"><?echo '<p><label for="school"><strong>School : </strong></label><select name="school" id="school">'."\n";$sql = "SELECT ID, School FROM School";$result = mysql_query($sql, $db);$count = mysql_num_rows($result);if($count == 0){ echo '<option>No Schools added yet.</option>';}while($row = mysql_fetch_assoc($result)){ echo '<option value="'.$row['ID'].'"'; if($_COOKIE[Cookie]['SchoolID'] == $row['ID']) { echo ' selected'; } echo '>'.$row['School'].'</option>'."\n";}echo '</select>';?><input type="submit" name="submit" value="Go" /></p></form></fieldset><p><?$var = $_COOKIE[Cookie]['SchoolID'];$sql = "SELECT ID, School, Address, Image FROM School WHERE ID = '$var'";$result = mysql_query($sql, $db);$count = mysql_num_rows($result);while($row = mysql_fetch_assoc($result)){echo '<a href="'.$row['Address'].'" title="'.$row['School'].'"><img src="'.$row['Image'].'" /></a>';}?></p>[/code]Above is the code i put in my php document. The piece of code below i have in a different document called setcookie.php. [code]<?php$School = $_POST['school'];setcookie("Cookie[SchoolID]", $School);header('Location: school.php');?>[/code]Any help with this would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/36410-how-do-i-set-a-my-cookie-with-a-time-limit/ Share on other sites More sharing options...
fert Posted January 31, 2007 Share Posted January 31, 2007 [code]setcookie("Cookie[SchoolID]", $School,$time);[/code] Link to comment https://forums.phpfreaks.com/topic/36410-how-do-i-set-a-my-cookie-with-a-time-limit/#findComment-173219 Share on other sites More sharing options...
Jessica Posted January 31, 2007 Share Posted January 31, 2007 manual...http://us2.php.net/set_cookiethe expire arg. Read the examples. Link to comment https://forums.phpfreaks.com/topic/36410-how-do-i-set-a-my-cookie-with-a-time-limit/#findComment-173220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.