Jump to content

reseting $_COOKIE expiration


jmr3460

Recommended Posts

Hello All,

I have a calendar that I am adding edit capabilities to. I am using cookies to give user that ability. I set the cookie expiration to the date of the event. I now have run into an issue that if the same user adds another event that is one month or more before the first event then the second cookie's expiration is changed to the second date. The possibly is that 3 or 4 or 5 event dates could be added by the same user.  I can call all of these dates from the table, is there a function that selects the greatest value in an array or something like that?

Link to comment
Share on other sites

Hey it worked. About the cookie thing. This calendar has only about 20 or so events in the future. I am just giving the users of this calendar an option to be able to edit their own events. I have warned them about having to accept cookies and only being able to edit from the computer they added the event from. If the calendar becomes more busy in the future I will use mysql to allow users to login and edit. Another reason that I am using cookies are that some of these people will not add events if they have to work for it.

This is how I solved my problem with my cookies:

<?php
$email = $_COOKIE['email'];
$connection = mysql_connect("localhost", "user", "pw") or trigger_error(mysql_error());
$db_name = "arscnaor_calendar";
$db = mysql_select_db($db_name, $connection) or trigger_error(mysql_error());
//This is the time function to find the greatest time for any $email
$sql = "SELECT date FROM calendar WHERE email = '$email' AND first_day = 1";
$query = mysql_query($sql) or trigger_error(mysql_error());
while($result = mysql_fetch_array($query)){
$times = strtotime($result['date']);
}
$max = max(array($times));
setcookie("test", $email, $max, "/", ".site.org");
?>

If there is a faster or more efficient way I am more that willing to try it.

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.