good day everyone,I want to develop a login page with username and password.if the user uses the account two times, let the account be disable.that is if the user tries to use the account the 3rd time she will recieve an error message that the account is no longer valid that she has to get new username and password.
thanks
8 replies to this topic
#1
Posted 01 February 2011 - 05:52 PM
|
|
|
#2
Posted 01 February 2011 - 06:32 PM
#3
Posted 01 February 2011 - 06:36 PM
You can store their login count in a tinyint column named logincount.
On login:
On login:
- Check if logincount is <= 2. True? display message. False? allow login.
- Update the count, "UPDATE tbl_users SET logincount = logincount + 1 WHERE uid = $uid"
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 02 February 2011 - 01:12 PM
Thanks for your reply, this is what i have so far. how do i proceed
<?
if( !isset($_SESSION) ) { session_start(); }
$database_db="crown";
$user_db="root";
$password_db="root";
$host_db="localhost";
$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()); ;
$userid=$_POST["userid"];
$password=$_POST["password"];
$errormessage = "";
$sql="SELECT * FROM usertab where userid='$userid' and password='$password'";
$result = mysql_query($sql, $link) or exit('$sql failed: '.mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows==0){
header("Location: error.php");
} else {
header("Location: test/add.php");
exit;
}
?>
#5
Posted 02 February 2011 - 03:44 PM
$sql="SELECT * FROM usertab where userid=[COLOR=RED]'$userid' and password='$password'[/COLOR]";
Bad idea. This leaves you vulnerable to SQL injection, which can blow away your entire database. Definitely sanitize your input before running it, i.e. scan for invalid characters like * / \ | & and so on, and reject the input as necessary.
sudo rm -rf /
#6
Posted 02 February 2011 - 05:53 PM
One way is to append AND count <= 2 to the query that checks their login credentials, assuming you have set up a tinyint column named "count".
Then on successful login before header("Location: test/add.php") you may add another query, such as
UPDATE usertab SET count = count + 1 WHERE userid = '$userid'
Also Dargueta is right, you must escape your variables for data integrity:
Then on successful login before header("Location: test/add.php") you may add another query, such as
UPDATE usertab SET count = count + 1 WHERE userid = '$userid'
Also Dargueta is right, you must escape your variables for data integrity:
$userid = mysql_real_escape_string($_POST["userid"]);
$password = mysql_real_escape_string($_POST["password"]);
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.
#7
Posted 05 February 2011 - 08:39 PM
thanks for your response.
I tried to add it as shown in the code below but it displays an error. Secondly how and where can i add this count <=2 in the code
please can you help me to fix it where it should be thanks
I tried to add it as shown in the code below but it displays an error. Secondly how and where can i add this count <=2 in the code
<?
if( !isset($_SESSION) ) { session_start(); }
$database_db="crown";
$user_db="root";
$password_db="root";
$host_db="localhost";
$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()); ;
$userid=$_POST["userid"];
$password=$_POST["password"];
$errormessage = "";
$sql="SELECT * FROM usertab where userid='$userid' and password='$password'";
$sql="UPDATE usertab SET count = count + 1 WHERE userid = '$userid'";
$result = mysql_query($sql, $link) or exit('$sql failed: '.mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows==0){
header("Location: error.php");
} else {
header("Location: test/add.php");
exit;
}
?>
please can you help me to fix it where it should be thanks
#8
Posted 05 February 2011 - 10:38 PM
To the first query, you also need to bring the second query right before the header("Location: test/add.php"); line and of course execute them both separately.
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.
#9
Posted 16 February 2011 - 07:03 PM
I have work the code as you said. Now the code only count or update the number of times the user logged in. I like I said earlier, my intention was to make users login account invalid on 2nd time login.That is if the user use the account 2 times,it will be invalid and she will be ask to produce another username and password. below is the updated code
thanks
thanks
<?
if( !isset($_SESSION) ) { session_start(); }
$database_db="cat";
$user_db="root";
$password_db="root";
$host_db="localhost";
$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()); ;
$userid=$_POST["userid"];
$password=$_POST["password"];
$errormessage = "";
$sql="SELECT * FROM usertab where userid='$userid' and password='$password'";
$sql1="UPDATE usertab SET count = count + 1 WHERE userid = '$userid'";
$result1=mysql_query($sql1);
$result = mysql_query($sql, $link) or exit('$sql failed: '.mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows==0 AND $count <= 2){
echo "error <BR>";
}
else {
header("Location: insert1.php");
exit;
}
?>
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









