thanks for the replies,
my query is that i have used session_register('$var'); but i am not able to retrieve the value when i am going to other pages.Also when i am checking if(session_is_registered('user')) the answer is always true.
admin_login.php
Code:
<div id="main2">
<div>
<h2>Admin Login</h2>
<p> </p>
<form action="log_code.php" method="POST">
<table width="100%" border="1" cellpadding="10" cellspacing="5 " bordercolor="#E0DFE3" >
<tr>
<td width="23%" id="t_uname">Username: </td>
<td width="77%"><input name="username" type="text" size="20" /></td>
</tr>
<tr>
<td id="t_pword">Password: </td>
<td><input name="password" type="password" size="20" /></td>
</tr>
<tr>
<td > </td>
<td><input type="submit" value="Submit" name="login"> <a href="changepw.php">Change password?</a></td>
</tr>
</table>
</form>
<p> </p>
</div>
</div>
log_code.php
Code:
<?PHP
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
//convert the field values to simple variables
//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
$pass = $_POST['password'];
$con = mysql_connect("localhost", "root", "");
if(!$con)
{
die("could not connect" . mysql_error());
}
mysql_select_db("db_dayak", $con);
$result=mysql_query("select * from registration where email='$user' AND password='$pass'");
//check that at least one row was returned
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0)
{
while($row = mysql_fetch_array($result))
{
//start the session and register a variable
session_start();
session_register('user');
$type=$row['type'];
$user=$row['email'];
$fn=$row['first_name'];
$ln=$row['last_name'];
$name= $fn.$ln;
if ($type=='employer')
{
include('employer.php');
}
else if ($type=='recruiter')
{
include('recruiter.php');
}
}
}
else {
//if nothing is returned by the query, unsuccessful login code goes here...
echo 'Incorrect login name or password. Please try again.';
}
?>
employer.php
Code:
<?php
//start the session
session_start();
//check to make sure the session variable is registered
if(session_is_registered('user')){
//the session variable is registered, the user is allowed to see anything that follows
$username=$user;
echo $username;
?>
<html>
<body>
Some code
</body>
</html>
<?php
}
else{
//the session variable isn't registered, send them back to the login page
echo "You have been logged out.Please login.";
}
?>
From employer.php or recruiter.php i have many subpages where i need to check is the user is logged in and also the username for retrieving mysql values.But i am not able to.
Please help if possible.
Thanks..Suk
Bookmarks