I already have have a members login script.... but i have to manually delete users.....what i reaaly need is to know how to make member expire after so many days with a php script. (free or very cheap) :cheesy:

Dani AI

Generated

As asked, the practical pattern is: keep expiry metadata in the database, run a scheduled script that processes expired rows, and make the operation safe (soft-delete + archive + logging) rather than immediately nuking data. That covers the ideas from , and but adds a reproducible, low-risk workflow and concrete examples you can adapt to Jpmaster77's script.

Add columns so expiration is explicit and indexed (this makes queries fast and policies flexible):

ALTER TABLE users
  ADD COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  ADD COLUMN expires_at DATETIME DEFAULT NULL,
  ADD COLUMN status ENUM('active','expired','deleted') NOT NULL DEFAULT 'active',
  ADD COLUMN deleted_at DATETIME DEFAULT NULL,
  ADD INDEX (expires_at);

Run a cronable PHP script that does a dry run first, then archives matching rows and marks them expired inside a transaction. Use PDO, prepared statements, and a short log so you can review what changed:

<?php
// (connect via PDO $pdo)
// select ids to expire
$sel = $pdo->prepare("SELECT id FROM users WHERE status='active' AND expires_at <= NOW()");
$sel->execute();
$ids = $sel->fetchAll(PDO::FETCH_COLUMN);
foreach($ids as $id){
  // copy to archive, then mark expired (use transactions)
}

Example cron line (adjust PHP path and paths for your host):

0 3 * * * /usr/bin/php -q /home/username/cron/expire_users.php >> /home/username/logs/expire.log 2>&1

Practical cautions: test with a dry-run flag, keep regular DB backups, exclude admins/paid users from expiry, respect timezone settings, place the script outside web root or restrict it to CLI, and log every change so accidental deletes are reversible. Sessions/cookies handle login state only — do not rely on them for permanent account expiry as hinted.

Recommended Answers

All 7 Replies

How much PHP do you know? You could just calculate the time length between the last login and registration time (if they've never logged in yet), or between the last two logins. If it equals x amount of time, then delete'em. How complicated is your current script? I could probably help you more if you give me more info on how much you know and what kind of script you're working with.

Use cookies for your login script. Set it for an expiring time for each user. Or simply use seesions if your good with PHP. Run the sessions from a MySQL Databse too, thatll help you keep track for sure how long they stay logged in or not.

I don't know much at all! I'm using a free script. (Jpmaster77's Login Script)
What I need is to auto delete users and passwords from Mysql database after
a certain number of days. I can't find a free script that will do that.
I read that I could write a php script that will do this.....(by using cron to execute
it), but I don't know much about cron either. :o

WEll, I hope my tutorial wll help you, by for now, its at my latest test site if you want to go look and read up on it, it might help you as far as Kill Cookies go or even sessions so that you wont have t odo it manually from the Database.

No registration as I said already that this is my test site.

I already have have a members login script.... but i have to manually delete users.....what i reaaly need is to know how to make member expire after so many days with a php script. (free or very cheap) :cheesy:

This really should not be too hard. Depending on how you have your login, what information you store there. Add a date/time stamp. Set some kind of variable somewhere else. When ever that user or someone else or have a seperate script for it...check the difference between when the user /account was created and now see if the time is bigger than the variable which states how long a user is valid...it doesn't get any cheaper than this...

aldo

1 word. Sessions!!

You could of course use sessions to maintain a users logged in period, but the deleting will need to be handled by a cron executed periodic script.
To do this you would simply need to add a tmie stamp to each users database entry stating when they last logged in.
The cron'd script would then run a database query regularly, (say daily or weekly or whatever you need) which would check each users timestamp, compare it to the current time, and if it exceeds your x amount of time, delete the database row (all users details).

Please read the following documentation for a thorough and clear tutorial on using crons http://www.webmasters-central.com/t/cron.shtml

Hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.