Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    setting something to expire with PHP

    I have a forum something similar to yahoo answers and I was wondering how I could set a particular question to expire after a certain amount of time. For example someone asks the question and then 3 days later it expires and is closed. I imagine that it is somehow related to a cron job but am not sure how the general proccess would go. could someone help me out with this?

  • #2
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    how about using server cookies? (can't remember if they exist in php)

    if time now = time then +3 days then expire

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    $_SESSION is the way to go
    You can not say you know how to do something, until you can teach it to someone else.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Uhhhh... Sessions do nothing for this, and I've never even heard of server cookies.

    You have to do this in a database, store the timestamp, and then as you mentioned use a CRON job to mark old questions as expired. The script runs every (1 hour, 1 day, depends on how important it is);

    select all questions from table where timestamp is older than 3 days, collect all IDs, then do an update set expired = 1 where ID in (1, 3, 5, etc.)

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks aedrin,


    That was along the lines of what I was thinking but didn't know if there was a better way of doing it. Thanks alot


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •