Jump to content

[SOLVED] creating a php script to log everyone off by CRON JOB


wmguk

Recommended Posts

Hey Guys,

 

I'm running a small site, and the office closes at 6pm so I want to run a cron job at 6.01pm to do a simple script.

 

Basically the DB has a users table, and one field is called "online"... I need to change this for all users in the table to "off"

 

I can get access to my server to set a cron job, but how do i make the script to set all users online=no?

 

Any thoughts?

 

 

Link to comment
Share on other sites

hahaha,

 

ok, scrub that...

 

just did a simple

 

<?
include ($_SERVER['DOCUMENT_ROOT'] . "/admin/scripts/scriptheader.php");

$sql="SELECT * FROM users"; 

$result=mysql_query($sql); 
while($row = mysql_fetch_array($result)) 
{
mysql_query("UPDATE users SET online = 'no'");
}
?>

Link to comment
Share on other sites

Hey Guys,

 

I'm running a small site, and the office closes at 6pm so I want to run a cron job at 6.01pm to do a simple script.

 

Basically the DB has a users table, and one field is called "online"... I need to change this for all users in the table to "off"

 

I can get access to my server to set a cron job, but how do i make the script to set all users online=no?

 

Any thoughts?

 

 

 

Umm...you just write your script to change the value from ONLINE to OFFLINE??

 

"UPDATE users SET online='offline' ";

 

 

Link to comment
Share on other sites

Hey Guys,

 

I'm running a small site, and the office closes at 6pm so I want to run a cron job at 6.01pm to do a simple script.

 

Basically the DB has a users table, and one field is called "online"... I need to change this for all users in the table to "off"

 

I can get access to my server to set a cron job, but how do i make the script to set all users online=no?

 

Any thoughts?

 

 

 

Umm...you just write your script to change the value from ONLINE to OFFLINE??

 

"UPDATE users SET online='offline' ";

 

 

 

yeah sorry - its late here and my brain seems to have left the office already!!

Link to comment
Share on other sites

ah, ok, i set it to 777 and i now get this error:

 

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 1: ?: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 2: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 2: //Host: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 3: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 3: //MySQL: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 4: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 4: //MySQL: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 5: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 5: //Database: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 7: syntax error near unexpected token `('

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 7: `$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());'

 

this is the script:

 

<?
$host = "localhost"; //Host name
$dbUser = "xxx"; //MySQL Username
$dbPass = "xxx"; //MySQL Password
$db = "xxx_xxx" ; //Database name 

$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());
mysql_select_db($db, $con) or die(mysql_error());

$sql="SELECT * FROM users"; 

$result=mysql_query($sql); 
while($row = mysql_fetch_array($result)) 
{
mysql_query("UPDATE users SET online = 'no'");
}
?>

Link to comment
Share on other sites

ah ok, that makes sense now! excellent, so I've now got it to run at 18.01 every day!

 

brilliant thank you...

 

One other thing, is there a way to automatically make an SQL dump of my entire database and set it as a cron job to save to a certain location on my webserver?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.