Sunday 17 August 2014

login script php

Posted by Unknown  |  No comments



                                 In this Post We will See Login Using Php Script
  Create a page login_1.php and add the following code

 

login_1.php
 <?php session_start();  
 $db=mysql_connect("localhost","root",'' ");  
 mysql_select_db("sample",$db);
  
 @$email=$_POST['email'];  
 @$password=$_POST['password'];  
 if(isset($_POST['submit'])) {  
 $sql="select * from clist where email='".$email."' and password='".$password."'";       
 $res=mysql_query($sql);  
 $nums=mysql_num_rows($res);  
 if($nums==1)  
 {  
      $result=mysql_fetch_array($res);  
      $_SESSION['email']=$result['email'];  
      $_SESSION['type']=$result['type'];  
      $_SESSION['id']=$result['id'];  
      header("location:next1.php");  
 }  
 else  
 {  
 echo "<script>alert('invalid details')</script>";       
 }  
 }  
 ?>  
 <style>  
 table {  
      background:#8FC283;  
      margin-top:150px;  
      border-radius:5px;  
 }  
 </style>  
 <form method="post">  
 <table align="center" border="0">  
 <tr><td>Email:</td><td><input type="text" name="email" id="email"></td></tr>  
 <tr><td>Password:</td><td><input type="password" name="password" id="password"></td></tr>  
 <tr><td align="center" colspan="2"><input type="submit" name="submit" id="submit" value="Login"></td></tr>  
 </table>   
 </form>  

next1.php:
 <?php session_start();  
 if (empty ($_SESSION['email']))  
 { 
header ('Location: login_1.php');;  
  }  
 echo "Welcome&nbsp;".@$_SESSION['email'];  
 ?>  
 <ul>  
 
 <ol><a href="logout11.php">Logout</a></ol>  
 </ul>  

 logout11.php:  
 <?php session_start();  
 session_destroy();  
 header("location:login_1.php");  
 ?>  

10:18 Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top