Session inside an iframe

If we are using an iframe in a page and we want to use the existing session variables of this page inside an iframe too, we must first register the session inside iframe with the same session id as the page including it.

Suppose we are including the file inside the page say current.php
This is done by including the file inside current.php in an iframe.

To set the same session id inside the iframe, we should first send the session id through GET method to the page we are including inside the iframe as below.


We then use the php function session_id() inside the included page too, supplying it the session id parameter that we obtained through GET method, to set the session id for the current session.

print_r($_SESSION); //This prints all the current session variables.

The paramater $sessid used in the function session_id() replaces the current session id inside the page included in an iframe. For this purpose, session_id() needs to be called before session_start().