SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb automaticly deleting MySQL entries after a set time

    can anyone help me or point me twards a way to set up a script that will delete a user after a specified period of time.

    I am trying to allow only 24 hours(1 day) access to a section of my site, and I want to be able to allow users to get a random password out of MySQL db but then it deletes after the specified time. Is it possible to do this?

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd setup a cron job. You might have to do it as a php file to determine which users to delete - say WHERE entrytime+86400 < UNIX_TIMESTAMP() (entry time also being a UNIX_TIMESTAMP()) - if you know what I mean.

    Sketch
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi~

    Thanks for the tip, I am running this on a Linux box w/ DarkOrbs Cpanel, they have a section for me to set up a Cron job, but no real documentation on what I need to do, so yeah, I do kinda know what cha mean, vern.

    I was wondering about setting up a field in my database(MySQL) that would automaticly add the timestamp + 86400 and then run a script (php) to update the record at the specified time.

    Only I am not sure how to schedule the php script to run, unless thats where the cron job comes in to play?

    thanks!

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, you would set up the crontab to execute the script at a certain time.

    Here is a link about setting up jobs that I found useful:

    http://www.superscripts.com/tutorial/crontab.html

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks that was just what i needed! lol

  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why not do it when someone access the page, so that if the date was registered and used in less than a 24 hour period it will delete. No cron jobs needed that way.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i am not sure how i would be able to track the time via the user, other than cookies, and not everyone has cookies allowed. cron job would be a gaurenteed way to prevent access after the alloted time frame. And logging ip address is not a fully effiecnt method due to dial up. At least that seems to be logical in theory. heh heh.

  8. #8
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use timestamp(14)

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would i build that into my header ? could you point me to a tutorial or resouce to elaborate that has an example? thanks oh mighty guru

  10. #10
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, when you create a table call a field timestamp

    ie

    create table users(
    id int(5) not null auto_increment,
    nick varchar(30) not null,
    date timestamp(14) not null,
    primary key(id)
    )

    http://www.mysql.com/doc/D/A/DATETIME.html

    Code:
    Column type  Display format  
    TIMESTAMP(14)  YYYYMMDDHHMMSS  
    TIMESTAMP(12)  YYMMDDHHMMSS  
    TIMESTAMP(10)  YYMMDDHHMM  
    TIMESTAMP(8)  YYYYMMDD  
    TIMESTAMP(6)  YYMMDD  
    TIMESTAMP(4)  YYMM  
    TIMESTAMP(2)  YY
    that will create the date when you insert a row, and when the user access's the page if the day has changed then do

    delete from ... where TIMESTAMP>...

    etc

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    see above
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool

    aggghhhh, your wetting my appitite for chaos! lol!

    thanks for that tidbit, searching thru the MySQL documentation is great, if you know what your looking for! I will give this idea a try and let you know if I can get it to work.


Bookmarks

Posting Permissions

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