Timothy Trisnadhama Timothy Trisnadhama - 1 month ago 6
PHP Question

$_SESSION, PHP, iframe, not getting the SESSION variables

I m creating a very simple PHP-based program for warehousing but quite complicated back-end process.

So here is the situation:




  1. I have the login page that directs to authorization page where it set the
    session_name
    for the first time,
    session_start()
    and set the session variables.

  2. After the authorization page, it goes to the main.php page that is a table with left hand side for menu (links) that I also did
    session_name()
    <-- same name as the one created from (1), and start the session.

  3. On the right hand side of the main page is the iframe that display the page when user click the links on the left. I also did
    session_name()
    <-- same name as the one created from (1), and start the session.



Problem:



main.php is ok, it reads the session variable perfectly, but the iframe couldn't get the session variables (i tried to
print_r($_SESSION)
, and came up empty). I tried
var_dump(session_name("abc"))
, where "abc" is the session name that i used in (1), and it does show "abc", tried (
isset($_SESSION)
) and returns true... so I don't know what am I doing wrong...




EDIT:
I m sorry guys, i think i may have found the culprit... it is a logic error on my side... i have this condition to check every php page i created to destroy session when the user level is not authorized to use this current page. My bad.. thanks so much for your help guys!!

Lan Lan
Answer

Make sure that session_start() is on all the pages:

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

see PHP manual reference

To control the contents of the $_SESSION try to put in all ifreame pages the code:

<?php 
   session_start();

   echo '<pre>';
   var_dump($_SESSION);
   echo '</pre>';
Comments