Hi Guys,... Wondering if you could please help me.. I want to be able to involve a "sleep" feature to my site.. Example; If a registered user has finished browsing the site and then clicks on their profile, i want them to be able to click a radio button that will put there account to "sleep"... This account would now be inactive for about 10 hours. Making other users unable to message or interact with them in anyway until the 10 hours has expired.. I am using PHP and MYSQL... Any help would be great.. Kinds Striker
This is the general idea: radio button as you said, once clicked, a mysql query will run and set inactive = 1 (example) at your message.php or interact.php (any interaction scripts) , first check for the status of the user. In this example, if inactive = 1 , the action cannot be continued. If inactive = 0 , the action can be, of course, continued. Regarding the 10 hours, you can store a time or timestamp into the users database. The timestamp will be the ending time of the inactivity (once the timestamp now is greater than the stored timestamp, means its over and the user is now active). Set the inactive = 0 (example) and proceed with the interaction things --- or you can ignore the inactive = x thing and just check for the timestamp in every interaction scripts.
Thanks ads2Help... you have made things a bit clearer for me.. i will have a play around with the timestamp and see how i go.. Thanks again
Wouldn't it be easier to just make a table called "sleeping_profiles" or something with following rows: id | userid | timestamp and then, when they click the checkbox, some ajax code calls a php file, that inserts the corresponding values into the database. Then check with: <? if(checkUserSleeping($_GET[id]){ echo "You can't message this user, because the user is sleeping"; } function checkUserSleeping($userId){ $userId = trim(addslashes(mysql_real_escape_string($userId))); $query = mysql_query("SELECT * FROM sleeping_profiles WHERE userid= '".$userId."' AND timestamp < date_sub(now(), INTERVAL 10 hour) ORDER BY id DESC LIMIT 1"); $count = mysql_num_rows($query); if($count == 0){ //If the user isn't sleeping return false; }else{ //The user is sleeping return true; } } ?> PHP: