Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php two sessions created

Status
Not open for further replies.

kellan4459

IS-IT--Management
Jul 3, 2003
84
US
I haven't found a definite answer to this on the forum but I have a page that verifies that the login is correct and if so it sets a session variable

if ( $success ) {
/* Username is set as a session variable with slashes */
session_start();
//session_register("username");

$_SESSION["username"] = $username;
header("Cache-control: private"); //IE 6 Fix

header("Location: ".URL_ROOT."applicant/index.php");
}

Once this occurs the applicant/index.php file does the following

<?php
session_start();
print_r($_SESSION);
echo session_id();
include("../defines.php");
include("verify_login.php");
include(COMMON."/dblogin.php");
include('handlers/indexhandle.php');
include(COMMON."/header.php");
?>
<table>
<tr>
<td valign="top" width="165">
<?php
include('indexLeftNav.php');
?>
</td>
<td>
<?php
include('in/indexIn.php');
?>
</td>
</tr>
</table>
<?php
include(COMMON."/footer.php");
?>

For some reason between the initial session_start() call and the call in applicant/index.php two sessions get created. The verify_login that is included in index checks to make sure the session variable is set and it checks the second session which is null so I then get my session timed out page and when I click to go back and login I can login fine and the session works throughout the site. I am trying to determine where this extra session is coming in but I haven't found anything on the forum that really says what is normally happening in this situation or anything that gives a strong debugging guide. It is working on a test server with w2k but trying to install on xp pro for demo purposes where internet isn't available.

Installation information
Apache 2.0.54
PHP 5.04
Windows XP

Thanks for the help
 
Try to write the session information before redirecting with session_write_close();
Unfortunately there are many reports in the PHP manual on the session_start page referring to this problem, especially on WinXP.
 
I changed the files to be in root/Site instead of root and I put a file in root called index.php that did a redirect to root/Site and modified my defines file pasted below to access this folder instead of the root. The session works fine, one is created and variables are set. Not sure why this is, I have read a lot of threads and pages but nothing has worked other than the fix I just said, any reason this works?

//defines.php

<?

//Turn off "undefined variable" error messages
error_reporting("E_ALL & ~E_NOTICE");

// defines
define ("ROOT", "c:\Apache/Apache2/htdocs/LovettSite/"); // path to root directory

define("SERVER_ADDR","define ("URL_ROOT", SERVER_ADDR."/LovettSite/");
define ("URL_COMMON", SERVER_ADDR."/LovettSite/common/");


// common directories
define ("COMMON", ROOT."LovettSite/common"); // path to root directory
define ("INCLUDES", ROOT."LovettSite/includes"); // path to root directory

?>
 
Have you inspected the settings for the session cookie? Use Firefox and inspect the cookie settings, maybe there is something with the path the cookie is valid for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top