Switch to full style
Project under GPL source codes are posted here
Post a reply

Login using session with php and mysql

Tue Dec 23, 2008 5:07 pm

 Project Name:   Session Login using php and mysql
 Programmer:   msi_333
 Type:   Web
 Technology:  Mysql ,php
 IDE:   None
 Description:   This program allow you to login and logout using session in php and mysql ,the source code is included as well as the database script .
simple.rar
php login using session
(2.06 KiB) Downloaded 7632 times

Code:
Authentication.php:

php code
<?php 
include 'header.php';


function Login($username, $password)
{
$query=" SELECT * FROM Account where username='$username' and password='$password'";
$result=mysql_query($query);
echo mysql_error();
$num=mysql_num_rows($result);
if($num==0)
{
return false;
}
else
return true;


}

$username=$_POST['username'];
$password=$_POST['password'];

if(Login($username,$password))
{
$_SESSION['username']=$username;
echo "Welcome :)".$username ;
?>
<a href="index.php" >Home</a>
<?

}
else
{
echo "<center><b> Wrong username and password </b></center> " ;
}




?>


Code:
Config.php

php code
<?php
$servername='localhost'; // Your MySql Server Name or IP address here
$dbusername='root'; // Login user id here
$dbpassword=''; // Login password here
$dbname='IBM'; // Your database name here
global $link;
connecttodb($servername,$dbname,$dbusername,$dbpassword);


function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{

$link=mysql_connect ("$servername","$dbuser","");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}


?>


Code:
Login.php

php code
<? 
include 'header.php';

?>

<form action="Authentication.php" method="post">


<b>Username : </b><input type="text" name="username" size="30" /><br/>
<b>Password : </b><input type="password" name="password" size="30" />
<input type="hidden" name="login" value="x1" />
<input type="submit" value="Login" />


</form>


<?




?>


Code:
logout.php

php code
<? session_start();

unset($_SESSION['username']);
?>


Code:
Header.php

php code
<?php   session_start();
include "config.php";

if(!isset($_SESSION['username']))
{
?>
<a href="Login.php" />Login </a>
<?
}
else
{
echo "welcome ".$_SESSION['username'];

?>
<a href="Logout.php" />Logout </a>
<?
}

?>

Code:
index.php

php code
<? 
include "Header.php";


?>




Re: Login using session with php and mysql

Thu Jun 07, 2012 1:46 am

Good :)


Re: Login using session with php and mysql

Sun Jan 20, 2013 5:00 pm

updated.

Post a reply
  Related Posts  to : Login using session with php and mysql
 php login with session     -  
 track session from login page-J2EE project     -  
 Login page using sessions and mysql in php     -  
 develop a login page- login servlet - ServletContext     -  
 login using jsp     -  
 session in jsp     -  
 ASP.NET 2.0 Login Controls     -  
 Ajax Login     -  
 login using Ajax     -  
 PHP session variables     -  

Topic Tags

PHP Sessions, PHP Forms, PHP Database