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","root","")
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='$username'";
$result=mysql_query($sql)
or die("Cannot execute query");
$num=mysql_num_rows($result);
if($num==1) //username valid
{
$sql="select username from company where username='$username' and password='$password'";
$result2=mysql_query($sql)
or die("Cannot execute query");
$num2=mysql_num_rows($result2);
if($num2>0)
{
setcookie("Username", $username, time() + 60 * 60 * 24 * 365);
$today= date("D F d, h:ia");
include("welcome.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_login.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_login.php");
}
?>[/PHP]
WELCOME PAGE
[PHP]<html>
<head>
<title>Welcome</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("homepage.php");
?>
</body>
</html>[/PHP]