Jump to content

PHP session trouble


putty

Recommended Posts

I am having trouble keeping a session variable, I have a login script that when authenticated sets

 

$_SESSION['uid'] = $uid;
$_SESSION['password'] = $password;

 

I am using “php_value session.auto_start” set in my htaccess.dist file to automatically start my session for every page.

 

The problem is that the session value is not held if I navigate to another page $_SESSION['uid'] is empty.

 

Any suggestions why? Is this something to do with “php_value session.auto_start”?

 

Any help or suggestions of how to debut this problem would be much appreciated, my application goes live at the end of the week and I don’t think my users will appreciate having to type there username and password on every page.

 

PS. I am using AJAX to call my authentication script, if that makes a difference.

 

Thanks in advance,

Levi

 

Link to comment
Share on other sites

I am having trouble keeping a session variable, I have a login script that when authenticated sets

 

$_SESSION['uid'] = $uid;
$_SESSION['password'] = $password;

 

I am using “php_value session.auto_start” set in my htaccess.dist file to automatically start my session for every page.

 

The problem is that the session value is not held if I navigate to another page $_SESSION['uid'] is empty.

 

Any suggestions why? Is this something to do with “php_value session.auto_start”?

 

Any help or suggestions of how to debut this problem would be much appreciated, my application goes live at the end of the week and I don’t think my users will appreciate having to type there username and password on every page.

 

PS. I am using AJAX to call my authentication script, if that makes a difference.

 

Thanks in advance,

Levi

 

 

Turn off the auto_start on sessions and just start the sessions yourself.  Auto-starting them creates unnecessary overhead on pages that don't require sessions.  And on the other page, the one that has no session vars, do this:

print_r ($_SESSION);

 

And tell us the output.

Link to comment
Share on other sites

Ok the problem seems to be with “php_value session.auto_start” if I use session_start(); instead it seems to work, however I get a warning,

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/duguljambula/index.php:1) in /var/www/duguljambula/index.php on line 2

 

I can hide this warning with @session_start() and everything works.

 

I don’t understand what is causing this warning and it may cause problems down the road.

 

session_start(); is the first thing called in my script, before headers are sent.

 

<?php
     session_start();
     require_once('./config.php');

    	//Header
  	require_once(_ABSPATH . 'content/layout/header.php');

$PAGE = $_INPUT[2];
if(!$PAGE){
	$PAGE = 'index';
}

if(file_exists(_ABSPATH . 'content/pages/'. $PAGE . '.php')){
	include_once(_ABSPATH . 'content/pages/'. $PAGE . '.php');
}else{
	include_once(_ABSPATH . 'content/error/404.htm');
}

//footer
require_once(_ABSPATH . 'content/layout/footer.php');

?>

 

I am using RewriteEngine to pass every script via the index page. Eg, “www.mysite.com/map” will call index.php with the page variable ‘map’ however I still get the same warning if I call the script directly .eg, www.mysite.com/index.php?page=map

 

Any thoughts or suggestions?

 

Yes, the AJAX may be causing the trouble.

 

There was another guy that was having trouble setting a cookie from a PHP script that was called by AJAX. Have you tried accessing this script from a regular webbrowser instead of AJAX?

 

It doesn’t seem to make any difference it I authenticate using AJAX or just in the index script. Thanks for the suggestion.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.