Tue Dec 23, 2008 5:07 pm
Authentication.php:
<?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> " ;
}
?>
Config.php
<?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());
}
?>
Login.php
<?
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>
<?
?>
logout.php
<? session_start();
unset($_SESSION['username']);
?>
Header.php
<?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>
<?
}
?>
index.php
<?
include "Header.php";
?>
Thu Jun 07, 2012 1:46 am
Sun Jan 20, 2013 5:00 pm
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
Powered by phpBB © phpBB Group.