Jump to content

How do i set a my cookie with a time limit?


jesse23

Recommended Posts

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.

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.