Total members 11838 |It is currently Thu Dec 03, 2020 11:27 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






 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 .
Attachment:
File comment: php login using session
simple.rar [2.06 KiB]
Downloaded 7398 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";


?>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Good :)




Author:

updated.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 3 posts ] 

  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     -  
 Ajax Login     -  
 login using Ajax     -  
 ASP.NET 2.0 Login Controls     -  
 EJB session bean     -  



Topic Tags

PHP Forms, PHP Database, PHP Sessions







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com