I have a functioning login page and a user CP and am having trouble setting session variables in the login.php file.
The variables are $_SESSION[‘eid’] $_SESSION[‘email’] $_SESSION[‘userlevel’].
[php]<?php
session_start();
require(‘dbconn.php’);
$message ="";
if (isset($_POST[‘submit’])) {
if(!$_POST['email'] | !$_POST['password']) {
$message = "Please enter your login details";
echo $message;
}
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$email = $_POST[‘email’];
$check = mysql_query(“SELECT * FROM employees WHERE email = “$email””)or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
$message = "<center>Email address not found, please contact your manager.</center>";
echo $message;
}
while($info = mysql_fetch_array( $check ))
{
$_POST[‘password’] = stripslashes($_POST[‘password’]);
$info['password'] = stripslashes($info['password']);
$_POST['password'] = md5($_POST['password']);
//gives error if the password is wrong
if ($_POST['password'] != $info['password']) {
$message ="<center>Incorrect Password</center>";
echo $message;
}
else
{
//if login details ok set session vars
$_SESSION[‘eid’] = $info[‘id’]; // difference between eid and id is correct
$_SESSION[‘email’] = $info[‘email’];
$_SESSION[‘userlevel’] = $info[‘userlevel’];
if($info[‘userlevel’] >= “2”)
{
header(“Location: usercp.php”);
} else {
header(“Location: usercp1.php”);
}
}
}
} else { //here is the html code for my login page.
echo $loginpage;
}
?>[/php]
The problem is when i try to call the variables in other pages it doesnt work.
I have a mysql query in a page called schedule.php which is displayed via an include() function within usercp.php.
[php]SELECT id, d, title, starttime, finishtime, FROM shifts WHERE m = $month AND y = $year AND eid = $sessionuser ORDER BY starttime[/php]
$sessionuser is the one which is the issue.
To test the functionality of my script I defined $sessionuser at the top of schedule.php.
[php]$sessionuser = “1”;[/php]
And this works. 1 being the eid of my test user account.
It’s when i try it this way when it doesn’t work:
[php]$sessionuser = $_SESSION[‘eid’];[/php]
I am assuming that I am doing something wrong in the post-submit login script when setting the variables.
Also to add I have included session_start(); at the top of any page which uses the vars and I have also tried it without.
Any help will be greatly appreciated as I have really hit a brick wall with this.
Thanks
Adam