• This is the Login form with a Username Text field and a Password field
<form action="verify.php" method="post" >
<tr> <td>UserName :</td><td><input type="text" name="username"      value=""/></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" value="" /></td></tr>
<tr><td /><td><input type="submit" name="login" value="Login" /></td></tr> 


This is the PHP script specified in the Form Action of the HTML Page,whose primary purpose is to authenticate a user is a verified user or not.

<pre>$dbHost = "localhost";//Location Of Database usually its localhost</pre>
<pre>$dbUser = "root"; //Database User Name</pre>
<pre>$dbPass = ""; //Database Password</pre>
<pre>$dbDatabase = ""; //Database Name</pre>
<pre>$db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database.");//Connect to the database</pre>
<pre>mysql_select_db($dbDatabase, $db)or die("Couldn't select the database."); //Selects the database</pre>
<pre>$usr = mysql_real_escape_string($_POST['username']);</pre>
<pre>$pas = mysql_real_escape_string($_POST['password']);</pre>
<pre>$sql = mysql_query("SELECT * FROM login_stud WHERE name='$usr' AND password='$pas' LIMIT 1");</pre>
<pre>if(mysql_num_rows($sql) == 1)</pre>
<pre>$row = mysql_fetch_array($sql);</pre>
<pre>$_SESSION['username'] = $row['name'];</pre>
<pre>$_SESSION['logged'] = TRUE;</pre>
<pre>echo "Login Successful";</pre>
<pre>header("Location:student_home.php"); // Modify to go to the page you would like</pre>
<pre>$_SESSION['logged']= FALSE;</pre>
<pre>echo "Login Failed";</pre>
<pre>//If the form button wasn't submitted go to the index page, or login page</pre>
<pre>header("Location: index.html");</pre>


    • Unsetting a Session Variable will lead to nullifying the session variables set
    • session_destroy() function will destroy the session

  • Note: Start the session again before destroying the variables in the logout page else an error will be specified.
Thank u for reading this  Article hope it was useful !
Sathesh BM

About Sathesh Bm

Sathesh Bm has written 26 post in this website.

Engineer, Web Lover, Thinker, Blogger

Related Posts Plugin for WordPress, Blogger...