cannot access session data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xldenis
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 8:30 pm

cannot access session data

Post by xldenis »

I am working on a script to edit the content of several pages with a mySQL database. to do that i pass session data from another page to indicate what table i should select. I know that the session write the data since, i print it out on the same page, but it is lost as soon as the page changes. (I made a counter that would increase by 1 every refresh but that got stuck at one). Here is my code:

Code: Select all

<?
session_start();
if(!isset($_SESSION['tbl'])){
    echo '<b><center>No Session Data Found, please return to main.php</center></b>';
    header('Location: main.php');
    $table='news';
                    }else{
$table=$_SESSION['tbl'];
                    }
 
?>
There is more to the file but i know that that works, no matter what i do i get my no session data message appearing. Help please?
Last edited by Benjamin on Fri May 29, 2009 10:26 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: cannot access session data

Post by califdon »

You might try putting in this line, to print out all the session variables:

print_r($_SESSION);
xldenis
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 8:30 pm

Re: cannot access session data

Post by xldenis »

it prints Array( )
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: cannot access session data

Post by shafiq2626 »

califdon wrote:You might try putting in this line, to print out all the session variables:

print_r($_SESSION);
Helo!
May Start session with this
@start_session();
also check you register session or not
xldenis
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 8:30 pm

Re: cannot access session data

Post by xldenis »

yeah.. i checked the session id's and they are different for the two pages.
xldenis
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 8:30 pm

Re: cannot access session data

Post by xldenis »

I set my SESSION['tbl'] in a file called main.php. That however should not be of any importance because i know that the value is set since in main.php i echo $_SESSION['tbl'] to check because of the error..
xldenis
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 8:30 pm

Re: cannot access session data

Post by xldenis »

no, i did call the session_start(); i also moved it to the very top.. still didn't change anything. Is it possible that the server is somehow terminating the session as soon as the page changes?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: cannot access session data

Post by califdon »

xldenis wrote:it prints Array( )
That demonstrates that no session variables are set. So the problem lies in the script where you think you are setting them.
Post Reply