Complete login and sign up app on php


Complete login and sign up app on php

A complete Login and Sign up syastem project has given below.........
php login system


Requirements.....
                           1. A database( Test1.sql)
                           2. three table with the name username,password & email
                           3.index.php
                           4.login.php
                           5.register.php
                           6.logout.php  
                           7.menu.php
                           8.error_log.php
                           9.insert.php
                           10.view.php
                           11.connect.php


Now fill the .php files with following code......


1.index.php

 <?php
include("menu.php");
session_start();
@$_SESSION['auth'];
@$error=$_GET['error'];
?>
<style>
td#content:hover{
background: orange;
color:white;
}
td#content{
border-radius:1em;
border:solid 1px black;
}
a#register{
text-decoration:none;
color:black;
font-weight:bold;
}
a#register:hover{
 color:blue;
 text-decoration:underline;
}
</style>
<centeR>
<table width=1000 cellspacing=4 cellpadding=6>
<tr>
<td id=content  bgcolor="#eeeeee" valign=top width="250">

 <!-- check if session empty (user not logged in) display the login form else not display -->
 <?php if(empty($_SESSION['user'])) { ?>
 <b>Please login to your profile<br>
 <?php 
 $f = fopen("error_log.php","r");
 @$error = @fread($f, filesize("error_log.php"));
 echo $error;
 ?>
 </b><br><br>
 <form action="login.php?do=login" method="post" style="border-radius:1em;border:solid 2px green;padding:10px;">
 <table>
 <tr>
 <td><b> username: </td><td><input style="border:solid 1px black" type="text" name="username" ></td></tr>
 <tr>
 <td ><b> password: </td><td><input style="border:solid 1px black" type="password" name="password"></td></tr>
 <tr>
 <td colspan=2 align=right><a id="register" href="register.php" >new ? register</a> <input type=submit value=login ></td></tr>
 </table>
   
 </form>
 <?php
 } else
 echo "<B>Welcome ". $_SESSION['user'] ." you are logged in <a href=logout.php>click here to logout </a>";
 ?>
 <hr>
 <br>
 sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d
</td>
<td id=content bgcolor="#eeeeee" valign=top ><b>Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here <BR><BR>Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here <BR><BR>Any content you need to put it here Any content you need to put it here Any content you need to put it here Any content you need to put it here</b></td>
</tr>
</table>
<hr>
</table>
</center>



2.login.php


<?php
mysql_connect('localhost','root','');
mysql_select_db('test1');
//get the values
$username=addslashes($_POST['username']);
$password=addslashes($_POST['password']);
@$email=addslashes($_POST['email']);

$action = $_GET['do'];//get action from url
//perform login here
if($action == "login"){
  $q=mysql_query("select username from login where username='$username'");
  $found_username = 0;
  //check if username available
  while($f=mysql_fetch_array($q)){
    if($f['username'] == $username){
     $found_username = 1;
     break;
    }
  }
  //if username available go and check password
  if($found_username == 1){
    $q=mysql_query("select password,username from login where username='$username'");
    $found_password = 0;
    while($f=mysql_fetch_array($q)){
        if($f['password'] == $password){
            $found_password = 1;
            break;
        }
    }
    //if true password for the user login and open session
    if($found_password == 1){
     session_start();
     $_SESSION['auth'] = 'yes';
     $_SESSION['user'] = $username;
     $f1=fopen("error_log.php","w");
     //set file content to empty because user and pass are correct
     fwrite($f1,"");
     header("Location: index.php");
    }else {
    //copy the error message in a file
     $f=fopen("error_log.php","w");
     fwrite($f,"");
     fwrite($f,"your password is incorrect !!");
     header("Location:index.php");
  }
  }
  else {
  //copy the error message in a file
  $f1=fopen("error_log.php","w");
  fwrite($f1,"");
  fwrite($f1,"your username is incorrect !!");
  header("Location:index.php");
  }
}
//perform register here
if($action == "register"){
//check user if available in database before register
 $q=mysql_query("select username from login where username='$username'");
 $found = 0;
 while($f=mysql_fetch_array($q)){
    if($f['username'] == $username){
      $found = 1;
      break;
    }
 }
 //end check user
 if($found == 1)
  header("Location: register.php?error=found");
  //apply register and log user in and redirect to insert page
  //remember to open session in each page in user profile
 else{
  $q=mysql_query("insert into login values('','$username','$password','$email')");
  session_start();
  $_SESSION['auth'] = 'yes';
  $_SESSION['user'] = $username;
 
  header("Location: insert.php");
  }
}
?>



3.register.php


<?php
include("menu.php");
@$error = $_GET['error'];
?>
<style>
td#content:hover{
background: orange;
color:white;
}
td#content{
border-radius:1em;
border:solid 1px black;
}
a#register{
text-decoration:none;
color:black;
font-weight:bold;
}
a#register:hover{
 color:blue;
 text-decoration:underline;
}
</style>
<centeR>
<table width=1000 cellspacing=4 cellpadding=6>
<tr>
<td id=content  bgcolor="#eeeeee" valign=top width="250">

 <br>
 sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d
</td>
<td id=content bgcolor="#eeeeee" valign=top > <b>Please login to your profile</b><br><br>
 <form action="login.php?do=register" method="post" style="border-radius:1em;border:solid 2px green;padding:10px;">
 <table>
 <tr>
 <td><b> username: </td><td><input style="border:solid 1px black" type="text" name="username" ></td></tr>
 <tr>
 <td ><b> password: </td><td><input style="border:solid 1px black" type="password" name="password"></td></tr>
 <tr>
 <td ><b> email: </td><td><input style="border:solid 1px black" type="text" name="email"></td></tr>
 <tr>
 <td colspan=2 align=right> <input type=submit value=register ></td></tr>
 </table>
   
 </form></td>
</tr>
</table>
<hr>
<?php
if($error == "found")
 echo "<script>alert('User already registerd please choose another username')</script>";
?>
</center>


4.logout.php


<?php
session_start();
$_SESSION['auth'] = 'no';
session_destroy();
$_SESSION['user'] = '';
header("Location: index.php");
?>



5.menu.php



<center><table width=1000 >
<tr>
<td width=60><a id="menu" href="index.php">Home</a></td>
<td width=95><a id="menu" href="insert.php">Insert info</A></td>
<td width=100><a id="menu" href="view.php">View info</A></td>
<td width=750 align=right><b>Tutorial Web Login Application</b></td>
</tr>
</table>
<hr>
<center>
<style>
a#menu{
padding:10px;
color:white;
background:black;
text-decoration:none;
font-weight:bold;
border-radius:0.5em;
}
a:hover{
background: orange;
}
</style>



6.error_log.php

your username is incorrect !!


7.insert.php



<?php
include("menu.php");
 //remember to open session in each page in user profile
session_start();
@$_SESSION['auth'] = 'yes';
//check if not logged in return to home page
if(empty($_SESSION['user']))
 header("Location: index.php");
 //else view insert page content
else{
?>
<style>
td#content:hover{
background: orange;
color:white;
}
td#content{
border-radius:1em;
border:solid 1px black;
}
a#register{
text-decoration:none;
color:black;
font-weight:bold;
}
a#register:hover{
 color:blue;
 text-decoration:underline;
}
</style>
<centeR>
<table width=1000 cellspacing=4 cellpadding=6>
<tr>
<td id=content  bgcolor="#eeeeee" valign=top width="250">
 <B>insert info page
  <hr>
 <br>
 sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d sjd fkshg dfhsg dfjgs djfgs djfgsjfgs hdfsdh sdhgf ksgd fks dkfjsfksh fks dkjfh skjh d
</td>
<td id=content bgcolor="#eeeeee" valign=top ><b>Welcome <?php echo "<b>".$_SESSION['user']."</b>"; ?> you are logged in <a href="logout.php">click here to logout</a> <br>You can put a form here for insert data :D</b></td>
</tr>
</table>
<hr>
</table>
</center>
<?php
}
?>


8.view.php


<?php
include("menu.php");
 //remember to open session in each page in user profile
session_start();
@$_SESSION['auth'] = 'yes';
//check if not logged in return to home page
if(empty($_SESSION['user']))
 header("Location: index.php");
 //else view insert page content
else{
?>
<style>
td#content:hover{
background: orange;
color:white;
}
td#content{
border-radius:1em;
border:solid 1px black;
}
a#register{
text-decoration:none;
color:black;
font-weight:bold;
}
a#register:hover{
 color:blue;
 text-decoration:underline;
}
</style>
<centeR>
<table width=1000 cellspacing=4 cellpadding=6>
<tr>
<td id=content  bgcolor="#eeeeee" valign=top width="250">
 <b>View info page
  <hr>
 <br>

</td>
<td id=content bgcolor="#eeeeee" valign=top ><b>Welcome <?php echo "<b>".$_SESSION['user']."</b>"; ?> you are logged in <a href="logout.php">click here to logout</a> <br>You can put a form here for insert data :D</b><br>
<?php
 mysql_connect('localhost','root','');
 mysql_select_db("test");
 echo "<table width=600><tr><td bgcolor=green style='color:white;font-weight:bold;' >id</td><td style='color:white;font-weight:bold;' bgcolor=green >username</td><td style='color:white;font-weight:bold;' bgcolor=green >password</td></tr>";
 $q=mysql_query("select * from login");
 $color_var=0;
 while($f=mysql_fetch_array($q)){
 $color = $color_var == 1 ? "silver" : "skyblue";
  echo "<tr bgcolor=".$color."><td>".$f['id']."</td><td>".$f['username']."</td><td>".$f['password']."</td></tr>";
  $color_var=!$color_var;
 }
 echo "</table>";
 ?>
</td>

</tr>
</table>
<hr>
</table>
</center>
<?php
}
?>



9.connect.php

<?php
mysql_connect('localhost','root','');
mysql_select_db('test1');
?>


That's all.Please comment for any help .Special thanks:hussein huzimeh .


No Response to "Complete login and sign up app on php"

Post a Comment

leave a comment