PHP - Login

Very simple PHP script that can be included within a page to protect the content.
It is a basic script that I had implemented in the first approaches to web programming.

Language: PHP

Year: 2010

<?
/*Login pasw*/
$password[1] = "000"; 

/*Protected page's link*/
$link = "";
?> 

<?
if (!$submit) {
?>

<form action="<? $PHP_SELF ?>" method="POST">
Password:<br/>
<input name="pass" type="Password"><br/>
<input name="submit" type="submit" name="submit" value="Login">
</form>

<?
} else {
   if ($pass == null) {
   echo "Insert Password."; 
?> 

<form action="<? $PHP_SELF ?>" method="POST">
Password:<br/>
<input name="pass" type="Password"><br/>
<input name="submit" type="submit" name="submit" value="Login">
</form>

<?
  }
   else {
   if ($pass == $password[1]) {
      
   header('Location:'.$link);   
   }     
   //wrong username and password
   else {
    echo "Wrong password.";
?> 
<form action="<? $PHP_SELF ?>" method="POST">
Password:<br/>
<input name="pass" type="Password"><br/>
<input name="submit" type="submit" name="submit" value="Login">
</form>
<?
   }
  }
}?>

Tommaso Berlose

Software Engineer, Mobile and Front-end Developer, Traveler.

Ferrara, Italy