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.
Link to comment
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.