PHP Login Script

I Need Some Help With A PHP Script

If You Can I Would Like A Piece Of Code To Put In It:
After 3 Wrong Login Attempts To Not Allow Access To The Webpage

& If You Refresh It Will Load The Previous Webpage

So If Anyone Can Post A Suggestion Or More Preferred - A Piece Of PHP Script I Can Put In - Or Remake It For Me
I Would Be Most Obliged - Thank You :smiley:

[php]

Website Login <?php

// Website Password

$password = “Admin”;

// Website Display

print "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><h1 align=\"center\">Website Login</h1>";

// If The Password Is Valid - Let The User Access The Website

if ( isset ( $_POST[ “password” ] ) && ( $_POST [ “password” ] == “$password” ) ) {

print "<p align=\"center\">";
print "<b style=\"color: #00DD00;\">Login Successful!</b><br /></p>"; }

else {

// If The Password Is Invalid - Display An Error Message

if ( isset ( $_POST [ “password” ] ) || $password == “” ) {

print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password!</b></font></p>"; }
print "<form method=\"post\"><p align=\"center\"><b>Please Enter Your Password To Login</b>";
print "<br /><br />";
print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\">";
print "<input value=\" Login \" type=\"submit\"></p></form>"; }

?>

[/php]

Hi,

take one counter variable and store it into session. and every time check if that counter variable value is greater than 2. if it is then redirect it to previous page.

if($_SESSION[‘counter’] > 2) {
header(“Location:previouspage.php”);
}
if(!$_SESSION[‘counter’]) {
$counter = 0;
}

if ( isset ( $_POST [ “password” ] ) || $password == “” ) {
$counter++;
}

Ok Thanks For The Help :slight_smile:

The Script Now Looks Like This:

[php]

Website Login <?php session_start(); $_SESSION['counter']=0;

// Website Password

$password = “Admin”;
$_SESSION = “0”;

// Website Display

if ( $_SESSION [ ‘counter’ ] > 3) { header ( “Location:denied.php” ) ; }

if( !$_SESSION [‘counter’] ) { $counter = 0; }

if ( isset ( $_POST [ “password” ] ) || $password == “” ) { $counter++; }

print "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><h1 align=\"center\">Website Login</h1>";

// If The Password Is Valid - Let The User Access The Website

if ( isset ( $_POST [ “password” ] ) && ( $_POST [ “password” ] == “$password” ) ) {

print "<p align=\"center\">";
print "<b style=\"color: #00DD00;\">Login Successful!</b><br /></p>"; }

else {

// If The Password Is Invalid - Display An Error Message

if ( isset ( $_POST [ “password” ] ) || $password == “” ) {

print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password!</b></font></p>"; }
print "<form method=\"post\"><p align=\"center\"><b>Please Enter Your Password To Login</b>";
print "<br /><br />";
print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\">";
print "<input type=\"hidden\" name=\"counter\">";
print "<input value=\" Login \" type=\"submit\"></p></form>"; }

?>

[/php]

It Is Still Working As Usual,
But It Dosent Go To My Denied.php File
After 3 Login Attempts :’(

If This Can Be Fixed Please Post The Corrected Code ;D

Thank You

Sponsor our Newsletter | Privacy Policy | Terms of Service