PHP Session Variables - Disappear and Reappear

I have a template file containing all my headers, footers, and general information. It includes relevant content for the current page (two-stage presentation template).

I am trying to configure a login system using PHP session variables. I can set a variable, and sometimes they work, but sometimes they disappear. Clicking on links will sometimes make them return.

My site

Sign in with

username: test password: test

var_dumps session_id and $_SESSION above.

Click "Home." If session variables disappear, click on the home button (it may take up to 10 times) to view session information. Click on another navigation, and sometimes the session information gets up, and sometimes not.

Here is the session code at the top of my template file.

 <?php session_start(); require './classes/DBInterface.php'; $db = new DBInterface(); if($_REQUEST['submit'] == 'Login') { $username=$_POST['username']; $password=$_POST['password']; echo '-- login -- '.$username; $rs = $db->verify($username,$password,"admin",0); $admin = $rs->current(); if ($rs->valid()) { $_SESSION['username'] = $username; } } echo ' -- session id -- '; var_dump(session_id()); echo ' -- session var -- '; var_dump($_SESSION); 

I am using PHP5.

+6
php
source share
3 answers

If you use startlogic (it seems that?) For your hosting, you tried to do what they say in their FAQ: http://www.startlogic.com/knowledgebase/read_article.bml?kbid=600

They indicate this:

To start PHP sessions, include the following code at the top of any PHP script that uses sessions: session_save_path ("your path home directory" / cgi -bin / tmp); session_start ();

Maybe this will help? Especially if they use some kind of load balancer that balances / tmp but not your home directory?

+4
source share

If you use a load-balanced setting, perhaps only 1 of the N servers has the correct session data.

By default, session data is stored in the file system.
During the session, the file is stored in / tmp / and starts with "sess", followed by session_id

+2
source share

Are you absolutely sure that no one is calling before? I know that session_start () modifies the headers and also does not know why this is not working.

Go ahead and turn on the error report at the top of the script, just before the session_start () call, and see how this helps track this:

 error_reporting(E_ALL ^ E_NOTICE); ini_set('display_errors',1); session_start() 
+1
source share

All Articles