Cron Job Automate Social Network Web Site Maintenance PHP Tutorial

Cron Job Automate Social Network Web Site Maintenance PHP Tutorial

Listening Video

Learn to automate PHP MySQL web site maintenance tasks with Cron Jobs. You can set them to execute at any interval you like. In this example we create a PHP cron job that will delete all non-activate users after X days. If you do not clear the database of these users periodically your system will become clogged with non-activated users.
Lesson Code
<?php
require_once("../php_includes/db_conx.php");
// This block deletes all accounts that do not activate after 3 days
$sql = "SELECT id, username FROM users WHERE signup<=CURRENT_DATE - INTERVAL 3 DAY AND activated='0'";
$query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($query);
if($numrows > 0){
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
  $id = $row['id'];
  $username = $row['username'];
  $userFolder = "../user/$username";
  if(is_dir($userFolder)) {
          rmdir($userFolder);
      }
  mysqli_query($db_conx, "DELETE FROM users WHERE id='$id' AND username='$username' AND activated='0' LIMIT 1");
  mysqli_query($db_conx, "DELETE FROM useroptions WHERE username='$username' LIMIT 1");
    }
}
?>

Related Posts :

  • padding-top padding-top CSS padding-top Property The CSS padding-top property is used to create t… Read More...
  • margin margin CSS margin Property The CSS margin property is CSS shorthand for specifying&nb… Read More...
  • margin-bottom margin-bottom CSS margin-bottom Property The CSS margin-bottom property is used to cr… Read More...
  • padding-right padding-right CSS padding-right Property The CSS padding-right property is used to cr… Read More...
  • margin-left margin-left CSS margin-left Property The CSS margin-left property is used to create m… Read More...

0 Response to "Cron Job Automate Social Network Web Site Maintenance PHP Tutorial"

Post a Comment