我有这段代码在经过一段时间后删除未激活的用户,在这种情况下为7天。虽然脚本似乎根本不起作用?没有发生什么?当我删除重定向链接时,它只显示一个空白页面。尝试回应信息,但没有显示?
<?php
$dbhost = 'mysql.hostinger.co.uk';
$dbuser = 'u634727706_admin';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$checkdate= "SELECT username, signup_date FROM users WHERE activated='0'";
$checkdate2 = mysql_query($checkdate);
while($checkdate3 = mysql_fetch_array($checkdate2)){
$user = $checkdate3['username'].' ';
$date = $checkdate3['signup_date'].' ';
$start = strtotime("$date");
// get today's date
$today = strtotime("now");
// find difference (in seconds)
$time_elapsed = $today - $start;
// get days elapsed
$days_elapsed = $time_elapsed/86400;
if($days_elapsed >= 7){
mysql_query ("DELETE FROM users WHERE username='$user'") or die ("update didn't work");
echo '<meta http-equiv="refresh" content="0;url=http://basecentre.co.uk/admin.php?page=5&cron=3">';
exit();
}
}
echo '<meta http-equiv="refresh" content="0;url=http://basecentre.co.uk/admin.php?page=5">';
?>
答案 0 :(得分:3)
尝试在数据库中完成所有操作:
DELETE FROM users
WHERE activated = '0' AND signup_date < now() - interval 7 day;