Page 1 of 1

cannot access session data

Posted: Wed May 27, 2009 8:38 pm
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?

Re: cannot access session data

Posted: Wed May 27, 2009 9:55 pm
by califdon
You might try putting in this line, to print out all the session variables:

print_r($_SESSION);

Re: cannot access session data

Posted: Wed May 27, 2009 10:15 pm
by xldenis
it prints Array( )

Re: cannot access session data

Posted: Wed May 27, 2009 11:24 pm
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

Re: cannot access session data

Posted: Thu May 28, 2009 6:58 am
by xldenis
yeah.. i checked the session id's and they are different for the two pages.

Re: cannot access session data

Posted: Thu May 28, 2009 5:46 pm
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..

Re: cannot access session data

Posted: Thu May 28, 2009 10:40 pm
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?

Re: cannot access session data

Posted: Fri May 29, 2009 1:55 pm
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.