I want 2 use session in my login, but i never use session before. How to change my code as below if i want to use session... Can somebody give me some opinion, please.. Thanks a lot.. Below is my php code..
LOGIN FUNCTION
[PHP]<?php
extract ($_POST);
mysql_connect(" localhost","roo t","")
or die("Cannot connect to the server");
mysql_select_db ("ums e-job portal")
or die("Cannot connect to the database");
$sql="select username from company where username='$user name'";
$result=mysql_q uery($sql)
or die("Cannot execute query");
$num=mysql_num_ rows($result);
if($num==1) //username valid
{
$sql="select username from company where username='$user name' and password='$pass word'";
$result2=mysql_ query($sql)
or die("Cannot execute query");
$num2=mysql_num _rows($result2) ;
if($num2>0)
{
setcookie("User name", $username, time() + 60 * 60 * 24 * 365);
$today= date("D F d, h:ia");
include("welcom e.php");
}
else //message send to emp_login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("emp_lo gin.php");
}
}
elseif($num==0) //message send to emp_login.php when username not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("emp_lo gin.php");
}
?>[/PHP]
WELCOME PAGE
[PHP]<html>
<head>
<title>Welcom e</title>
</head>
<body>
<h1 align="center"> <?php echo $username; ?>, welcome to UMS e-Job Portal!</h1>
<h3 align="center"> You have been logged in since: <?php echo $today; ?>. </h3>
<?php
include("homepa ge.php");
?>
</body>
</html>[/PHP]
LOGIN FUNCTION
[PHP]<?php
extract ($_POST);
mysql_connect(" localhost","roo t","")
or die("Cannot connect to the server");
mysql_select_db ("ums e-job portal")
or die("Cannot connect to the database");
$sql="select username from company where username='$user name'";
$result=mysql_q uery($sql)
or die("Cannot execute query");
$num=mysql_num_ rows($result);
if($num==1) //username valid
{
$sql="select username from company where username='$user name' and password='$pass word'";
$result2=mysql_ query($sql)
or die("Cannot execute query");
$num2=mysql_num _rows($result2) ;
if($num2>0)
{
setcookie("User name", $username, time() + 60 * 60 * 24 * 365);
$today= date("D F d, h:ia");
include("welcom e.php");
}
else //message send to emp_login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("emp_lo gin.php");
}
}
elseif($num==0) //message send to emp_login.php when username not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("emp_lo gin.php");
}
?>[/PHP]
WELCOME PAGE
[PHP]<html>
<head>
<title>Welcom e</title>
</head>
<body>
<h1 align="center"> <?php echo $username; ?>, welcome to UMS e-Job Portal!</h1>
<h3 align="center"> You have been logged in since: <?php echo $today; ?>. </h3>
<?php
include("homepa ge.php");
?>
</body>
</html>[/PHP]
Comment