Jump to content

Recommended Posts

??? I just started having a problem with $_SESSION.  I start each script with <?php session_start(); ?> as the top line.

 

I use the standard $_SESSION['abc']=123 format.  Everything has been working perfect ... until just recently.  Now when I move from one script to another, the information stored in ALL SESSION VARIABLES disappears!!!  I am running PHP ver 5.1.6.

 

ANY HELP WOULD BE GREATLY APPRECIATED!!!  I am somewhat new to PHP and have no idea how to proceed...

 

It is not limited to a single script... ALL of my scripts are having the same issues with the SESSION variables disappearing.

Link to comment
https://forums.phpfreaks.com/topic/147785-problem-with-_session/
Share on other sites

I had a similair problem before...

Firstly have you turned on error reporting for php in the .ini file?

Second have you changed anything since it stopped working? if so what?

 

Have you re-installed php at all?

This was my problem I did a manual install of it and didnt point the directory for storing sessions in the .ini file. So check the path for sessions in your .ini file.

 

Make sure you have no white space before <?php and after ?>, and between <?php session_start();

 

I looked at my phpinfo and cannot see where or how the path is set for sessions in php.ini.  Can you tell me what directives I should be looking for?

 

I am using a shared hosting server so I cannot re-install PHP

 

I have not changed anything in the php.ini file that could make it stop working.  I set safe mode to off but that should have no effect.

My phpinfo does NOT contain any directives containing the word SESSION much less session_save_path.  Should this be in there?  Where should the save path be set to (if it was there)?

 

I started trying to write a cookie and then read it.  That does not work either!  In fact, after using setcookie("abc",123) I should be able to view the cookie fin the browser... lot's of cookies but not this one!

 

Something very weird is going on.  What course of action should I take??

Your setcookie is wrong.

 

You can try using .htaccess or even ini_set to set the session save. But if your host has sessions disabled, then yea. You have no control over that.

 

Check the phpinfo and see if there is a section called "SESSIONS" that states "disabled" under it. Sessions should be default on most php builds unless they turned it off.

I ran the following script...

 

<?php

 

echo ini_get('session.cookie_path');

echo "<br>".ini_get('session.name');

echo "<br>".ini_get('session.use_cookies');

echo "<br>".ini_get('session.save_path');

echo "<br>".ini_get('session.save_handler');

 

 

?>

 

and got the following output...

 

/

PHPSESSID

1

/var/lib/php/session

files

 

 

Based on this, it appears that SESSION is set and active???

Sounds like a header issue and that output buffering might have been on in php.ini and has been turned off.

 

Add the following two lines immediately after your first opening <?php tag on any page you are setting or referencing a session variable or on your page where you are attempting to use setcookie() -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

 

I have two very simple scripts to test this out...

 

test99.php...

 

<?php session_start(); ?>

 

<?php

ini_set ("display_errors", "1");

error_reporting(E_ALL);

include_once "functions.php";

$_SESSION['abc']=4444;

jumpto1('test100.php');  // jumpto1 is a function that is a few javascript lines that redirects the browser...

 

?>

 

and test100.php...

 

<?php session_start(); ?>

 

<?php

ini_set ("display_errors", "1");

error_reporting(E_ALL);

print_r($_SESSION);

die();

echo ini_get('session.cookie_path');

echo "<br>".ini_get('session.name');

echo "<br>".ini_get('session.use_cookies');

echo "<br>".ini_get('session.save_path');

echo "<br>".ini_get('output_buffering');

 

?>

 

the output is...

 

Array ( )

 

Warning: Unknown: open(/var/lib/php/session/sess_is7n6l58jfuelf2t172cahnto5, O_RDWR) failed: Permission denied (13) in Unknown on line 0

 

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

 

//////////////////////////////////////////

 

 

 

session.save_path is set to /var/lib/php/session

 

 

 

on your part where you put this:

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
print_r($_SESSION);
die();

 

you need to change the $_SESSION to $_SESSION['abc'].

 

Also in your .ini file check this:

 

; Whether to use cookies.
session.use_cookies = 1

and

; Name of the session (used as cookie name).
session.name = PHPSESSID

 

If this fails to work, you could try turning on automatic sessions with this in the .ini file:

 

; Initialize session on request startup.
session.auto_start = 1

 

If it works when you do this then there is probably error with your code.

 

remember to re-start apache.

 

check this too:

 

; Handler used to store/retrieve data.
session.save_handler = files

 

Why not just change the session.save_path to be within your own directories then make that directory be protected by you.

 

This is preferred especially on a shared host.

 

You should be able to use .htaccess to change where the session saves the data at.

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.