Jump to content

login security php


atck

Recommended Posts

correct this code


[code]<div id="SignIn">
<form method="post" action="web.php?insert=ok">
<table width="350" border="0" bgcolor="#000077">
<tr>
<td colspan="2" style="font:bold">
<font color="#DDDDDD" style="font:large">web</font>
</td>
</tr>
</table>
<table width="350" border="0" class="alphabox">
<tr>
<td width="161" height="35">User Name: </td>
<td width="253" height="35">
<input type="text" name="username" />
</td>
</tr>
<tr>
<td height="36" width="161">Password: </td>
<td width="253" height="36">
<input type="password" name="password" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="Submit" name="Submit" value="    Login    " width="60">
</td>
</tr>
</table>
<table width="350" border="0">
<tr>
<td colspan="3">
<a href="pwd4got.php"><font size="2"> Forgot Password? Click here for assistance </font> </a>
</td>
</tr>
</table>
</form>
</div>[/code]
Link to comment
https://forums.phpfreaks.com/topic/28218-login-security-php/#findComment-129453
Share on other sites

[code]
<?php
//start session
session_start();

//define some variables
$username = "demo";
$password = "password";
$allow_attempt = 3;

//check attempt time(s)
if(isset($_SESSION['attempt']) && $_SESSION['attempt']>$allow_attempt){
echo "you tried more than $allow_attempt times !";
exit;
}

//check if user submit form
if(isset($_POST['Submit'])){
//firstly, assume username & password are incorrect
$loged_in = false;

//check username & password
if($_POST['username']==$username && $_POST['password']==$password){
$loged_in= true;
}

if($loged_in==true){
  echo "You are loged in<br>";

}else{
//if login incorrect, plus attempt time
$_SESSION['attempt']++;
header("Location: $_SERVER[PHP_SELF]");
}
}

if(!empty($_SESSION['attempt'])){
echo "Number of attempt : ".$_SESSION['attempt'];
}
?>
<div id="SignIn">
<form method="post" action="<?=$_SERVER['PHP_SELF']; ?>?insert=ok">
<table width="350" border="0" bgcolor="#000077">
<tr>
<td colspan="2" style="font:bold">
<font color="#DDDDDD" style="font:large">web</font>
</td>
</tr>
</table>
<table width="350" border="0" class="alphabox">
<tr>
<td width="161" height="35">User Name: </td>
<td width="253" height="35">
<input type="text" name="username" />
</td>
</tr>
<tr>
<td height="36" width="161">Password: </td>
<td width="253" height="36">
<input type="password" name="password" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="Submit" name="Submit" value="    Login    " width="60">
</td>
</tr>
</table>
<table width="350" border="0">
<tr>
<td colspan="3">
<a href="pwd4got.php"><font size="2"> Forgot Password? Click here for assistance </font> </a>
</td>
</tr>
</table>
</form>
</div>
[/code]

Remember,
The session will be destroy when user close browser then user can re attempt again
Link to comment
https://forums.phpfreaks.com/topic/28218-login-security-php/#findComment-129455
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.