<?php
if( !isset($_SESSION) ) { session_start(); }
$database_db="cat";
$user_db="root";
$password_db="root";
$host_db="localhost";
// connect to database
$link=mysql_connect($host_db,$user_db,$password_db) or die ("couldnot connect: ".mysql_error());
mysql_select_db($database_db, $link) or exit('Error Selecting database: '.mysql_error());
// escape user input for database protection
$userid = mysql_real_escape_string($_POST["userid"]);
$password = mysql_real_escape_string($_POST["password"]);
// get user count from database, as that is all we need
$user = "SELECT count FROM usertab WHERE userid='$userid' AND password='$password'";
$userres = mysql_query($user);
// fetch the single user row we had selected
$row = mysql_fetch_row($userres);
// check if the user exists first
if(mysql_num_rows($userres) != 0) {
// check if the user did not login or access the account for 2 days
if($row[0] 2*24) {
echo "Error - Your account has been closed.";
} else {
//successful login, increment count by one
mysql_query("UPDATE usertab SET count = count + 1 WHERE userid = '$userid'");
//redirect them to the page
echo "Should be redirected now";
}
} else {
//if their username and password returned nothing
echo "Error - Your account does not seem to exist.";
}
?>
I set 2*24 hours
8 replies to this topic
#1
Posted 19 February 2011 - 07:52 PM
Good day everyone. Mr Alexandra from this site has developed this code for me and I want to use it now for another purpose. I need to close users account if the user did not login or access the account for two days. Please how do i proceed. I modified Mr Alexander Codes as follows
|
|
|
#2
Posted 19 February 2011 - 08:06 PM
okay I now added this > 2*24*60. my question is will it work.
24 = hours
60 = minutes
2 = days
Thanks
24 = hours
60 = minutes
2 = days
Thanks
#3
Posted 19 February 2011 - 09:23 PM
Try running this on a separate page first, and only run it once (with the stuff you need to connect to the database above it)
Once that is done, timestamps should be updated each time the user logs in, and if they do not, we close their account (in this case simply delete it) and warn them of this, the following is lightly tested:
mysql_query("ALTER TABLE usertab ADD lastlogin timestamp NOT NULL DEFAULT NOW()");You would only run this once to alter the table.Once that is done, timestamps should be updated each time the user logs in, and if they do not, we close their account (in this case simply delete it) and warn them of this, the following is lightly tested:
<?php
if( !isset($_SESSION) ) { session_start(); }
$database_db="cat";
$user_db="root";
$password_db="cyberworld";
$host_db="localhost";
// connect to database
mysql_connect($host_db,$user_db,$password_db) or die ("couldnot connect: ".mysql_error());
mysql_select_db($database_db, $link) or exit('Error Selecting database: '.mysql_error()); ;
// escape user input for database protection
$userid = mysql_real_escape_string($_POST["userid"]);
$password = mysql_real_escape_string($_POST["password"]);
// get user count from database, as that is all we need
$user = "SELECT count, lastlogin FROM usertab WHERE userid='$userid' AND password='$password'";
$userres = mysql_query($user);
// fetch the single user row we had selected
$row = mysql_fetch_row($userres);
// check if the user exists first
if(mysql_num_rows($userres) != 0) {
// check if the user has logged in 3 times already
if($row[0] > 2) {
echo "Error - You have logged in three times.";
// check if user has not logged in within two days in seconds
} elseif ((time() - strtotime($row[1])) > (2 * 24 * 60 * 60)) {
echo "Error - You have not logged in within two days";
// close the account (delete it for example)
mysql_query("DELETE FROM usertab WHERE userid = '$userid'");
} else {
//update their last login
mysql_query("UPDATE usertab SET lastlogin = NOW() WHERE userid = '$userid'");
//successful login, increment count by one
mysql_query("UPDATE usertab SET count = count + 1 WHERE userid = '$userid'");
//redirect them to the page
header("Location: insert1.php");
}
} else {
//if their username and password returned nothing
echo "Error - Your account does not seem to exist.";
}
?>
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#4
Posted 22 February 2011 - 06:59 PM
Thanks Mr. Alexander everything is working fine. Your code is excellent. I really appreciate your style. Please Mr Alexander is it possible to enable the users account after 2 days account expiration.let say a link eg enable.php where one can enter only the username to enable the account back until if the user do not make use of the account, it will lock again.
thanks
thanks
#5
Posted 22 February 2011 - 07:22 PM
All you would need to do is make enable.php update their last login again so it is within the last two days, for example:
Then they will be able to log in, try coding it and I will help if something goes wrong!
mysql_query("UPDATE usertab SET lastlogin = NOW() WHERE userid = '$userid'");
Then they will be able to log in, try coding it and I will help if something goes wrong!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#6
Posted 22 February 2011 - 08:15 PM
Thanks very much I have implemented it and now waiting for at least 24 hours to see the result because i set it to 1 * 24 * 60 * 60 ,. thanks a lot. Please Mr. Alexander , Are good in java I mean jsp/servlets
thanks
thanks
#7
Posted 22 February 2011 - 09:44 PM
I do not know servlets or Java, although you can feel free to post in our Java help section and see if somebody does.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#8
Posted 23 February 2011 - 12:20 PM
Thanks and remain bless
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









