When I logout as one user and log in under a different user, it opens with the last user's information.
User 1 - Unsername: Davey Jones
User 2 - Unsername: David Smith
I log out from Davey Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David Smith's. So something is amiss but I don't know what.
(BTW, this login script is based on the one found in Larry Ullman's book "PHP and MySQL for dynamic websites 2nd edition - Chapter13.)
Here's what I'm trying to do. I use a functions.php page that contains my core website and I call it on every single Web page. For instance on the index.php page it'll have this at the top and bottom of the page:
In between the top and bottom is the content for that page.
The login scripts are located in a folder called "members" - /mysite.com/members/login.php
The pages in the members folder has this at the top of each page:
The exception here would the index.php, register and login.php pages which would have real_login_chec k() function instead of the login_check() and main_bar() functions.
The sess.php contains:
The top.php contains:
These php pages are located in a folder called "includes" under the root directory - /mysite.com/members/includes/sess.php
The js_function.php page is located in the members folder.
The js_functions.ph p contains:
The index.php, register.php and login.php pages in the members folder are the only pages that uses the real_login_chec k(); function. If the user is logged in they will be directed to the main.php page which contains the information pertinent to them. If the person isn't logged in the login form will be displayed or the registration form in the case of register.php.
I tried to get cute and place a login form at the top of the functions.php page to eliminate the need to first go to the member's area to log in. If the user is logged in the welcome message is displayed instead of the login form. Here is that bit of code:
I want to enable sessions for many of the pages in the root directory, so I have this at the top of each page:
In the functions.php page I have the footer() function that contains this:
Since the pages in the members folder also calls the functions.php page they too have the ob_end_flush() function.
So, back to my problem of the last user "logged out" being carried over when someone else logs in. I'm not sure where the problem lies. I think I have listed everything here in this post that relates to logging in and sessions. These are the variables that are set when logging in:
I really don't understand the -10 in the code found in the functions.php page:
Does the -10 set the logging out for 10 minutes in the past to make logging out instantaneous?
I would like to keep the logging in feature at the top of all the pages. It's much like the one on this website and I find it quite handy. But if this is what is causing my logout and login problems, and if it can't be fixed I'll scrap it.
Thanks for any help.
David
User 1 - Unsername: Davey Jones
User 2 - Unsername: David Smith
I log out from Davey Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David Smith's. So something is amiss but I don't know what.
(BTW, this login script is based on the one found in Larry Ullman's book "PHP and MySQL for dynamic websites 2nd edition - Chapter13.)
Code:
// Welcome the user (by name if they are logged in).
echo '<h1>Welcome';
if (isset($_SESSION['first_name'])) {
echo ", {$_SESSION['first_name']}!";
}
echo '</h1>';
Code:
[b]At Top of Page[/b]
<?php
ob_start();
// Initialize a session.
session_start();
$page_title = "Home";
include('includes/config.inc.php');
include('functions.php');
do_html_header($page_title);
?>
[b]At Bottom of Page[/b]
<?php
bottom();
footer();
?>
The login scripts are located in a folder called "members" - /mysite.com/members/login.php
The pages in the members folder has this at the top of each page:
Code:
[b]At Top of Page[/b]
<?php
include('./../includes/sess.php');
include('./../includes/config.inc.php');
include('js_functions.php');
$page_title = 'Member Control Panel';
include('./../includes/top.php');
login_check();
main_bar();
The sess.php contains:
Code:
<?php // This page begins the HTML header for the site. // Start output buffering. ob_start(); // Initialize a session. session_start(); ?>
Code:
<?php
include("./../functions.php");
do_html_header($page_title);
echo "<h3>$page_title</h3><br>";
?>
The js_function.php page is located in the members folder.
The js_functions.ph p contains:
Code:
<?php
function welcome_bar()
{
echo "
<center>
<div style='width:95%; background-color:#EAF4FF; padding:3px'>
<strong>Welcome!</strong>
</div>
</center>
<br><br>
";
}
function pages_bar()
{
echo "
<center>
<div style='width:95%; background-color:#EAF4FF; padding:3px'>
Return to <a href='main.php'><u><strong>Member Control Panel</strong></u></a>
</div>
</center>
<br><br>
";
}
function main_bar()
{
echo "
<center>
<div style='width:95%; background-color:#EAF4FF; padding:3px'>
<strong>What would you like to do?</strong>
</div>
</center>
<br><br>
";
}
function login_check()
{
// If no user_id variable exists, redirect the user.
if (!isset($_SESSION['user_id']))
{
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) =='/') OR (substr($url, -1) == '\\') )
{
// Chop off the slash.
$url = substr ($url, 0, -1);
}
// Redirect to this page if not logged in.
$url .= './../members/login.php';
header("Location: $url");
// Quit the script.
exit();
}
else
{
// Welcome the user (by name if they are logged in).
if (isset($_SESSION['user_title']) && ($_SESSION['first_name']) && ($_SESSION['last_name']));
{
echo "
<p><strong>Hello:</strong> {$_SESSION['user_title']} {$_SESSION['first_name']} {$_SESSION['last_name']}</p>
";
}
}
}
function real_login_check()
{
// If user_id variable exists, redirect the user.
if (isset($_SESSION['user_id']))
{
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) =='/') OR (substr($url, -1) == '\\') )
{
// Chop off the slash.
$url = substr ($url, 0, -1);
}
// Redirect to this page if not logged in.
$url .= './../members/main.php';
header("Location: $url");
// Quit the script.
exit();
}
else
{
echo "
<center>
<div style='width:95%; background-color:#EAF4FF; padding:3px'>
<strong>Welcome!</strong>
</div>
</center>
<br><br>
";
}
}
?>
I tried to get cute and place a login form at the top of the functions.php page to eliminate the need to first go to the member's area to log in. If the user is logged in the welcome message is displayed instead of the login form. Here is that bit of code:
Code:
if (isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'members/logout.php'))
{
echo "
<strong>Hello, {$_SESSION['user_title']} {$_SESSION['first_name']} {$_SESSION['last_name']}</strong><br />
<a href='http://www.mysite.com/members/logout.php'>Logout</a><br />
<a href='http://www.mysite.com/members/index.php'>Member Control Panel</a>
";
}
else
{
// Not logged in
echo "
<form action='http://www.mysite.com/members/login.php' method='post'>
<strong>Member Login:</strong><br />
Email Address <input type='text' name='email' size='15' maxlength='45' value=''><br />
Password <input type='password' name='pass' size='10' maxlength='20'><br />
<input type='submit' name='submit' value='Login'>
<input type='hidden' name='submitted' value='TRUE'>
</form>
<br />
<a href='http://www.mysite.com/members/register.php'>Register</a>
";
}
Code:
<?php ob_start(); // Initialize a session. session_start();
Code:
</body></html>"; ob_end_flush();
So, back to my problem of the last user "logged out" being carried over when someone else logs in. I'm not sure where the problem lies. I think I have listed everything here in this post that relates to logging in and sessions. These are the variables that are set when logging in:
Code:
// Register the values & redirect. $row = mysql_fetch_array ($result, MYSQL_NUM); mysql_free_result($result); mysql_close(); // Close the database connection. $_SESSION['user_id'] = $row[0]; $_SESSION['email'] = $row[1]; $_SESSION['user_title'] = $row[3]; $_SESSION['first_name'] = $row[4]; $_SESSION['last_name'] = $row[5]; $_SESSION['city'] = $row[7]; $_SESSION['stateid'] = $row[8];
Code:
(substr($_SERVER['PHP_SELF'], -10) != 'members/logout.php')
I would like to keep the logging in feature at the top of all the pages. It's much like the one on this website and I find it quite handy. But if this is what is causing my logout and login problems, and if it can't be fixed I'll scrap it.
Thanks for any help.
David
Comment