head head body form methodPOST actionloginphp nameform1 table border0

Head head body form methodpost actionloginphp

This preview shows page 3 - 5 out of 6 pages.

Image of page 3
Create the authentication page Make a php page containing the following and save it as login.php <?php session_start(); if(!isset($_SESSION['username'])) { if(isset($_POST['username'])) { $dbname="single_signin"; $con=mysql_connect($host,$user,$password) or die ('Error connecting to mysql'); mysql_select_db($dbname,$con); $username=mysql_real_escape_srting( strip_tags ($_POST[username])); $password=mysql_real_escape_srting( strip_tags ($_POST[password])); $query="select * from user where username='$username' and password='$password‘"; $result=mysql_query($query,$con); $n=mysql_num_rows($result); $row=mysql_fetch_array($result); if($n < 1) { echo "<h2 style='color:red' align='center'>User name and password are not valid</h2>"; exit(); } else { $type='0'; $_SESSION['username']=$row[0]; if($row[2]=="1") $type='1'; if($row[2]=="2") $type='2'; $_SESSION['type']=$type; $_SESSION['log_in']="yes"; if($type==1) header("Location: admin.php"); else if($type==2) header("Location: user.php"); else header("Location: login.php"); } mysql_close($con); } } else {
Image of page 4
Image of page 5

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture