Session variables through frames - need help.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi there,

I have implemented a login sequence using session variables for a PHP/MySQL
DB which I took over development. I read some books and this NG and it
seemed straight forward. However the website I have taken over uses two
frames. The left hand side is always a navigation frame with the righthand
side of the screen always being the target.

I developed a main web page where login takes place and if successful a
session variable is set which all other pages look for before processing (if
it's not there they redirect to login page).

All seems to work OK from my PC until I use another frame as a URL
redirection to the PHP website. Therefore I want to use a nicer URL to where
the actual PHP website is hosted and so set another website to use frame
redirection to my PHP website DB.

When I do this the login session variables no longer seem to work and I can
no longer stay logged in. I assume this is something to do with where the
actual session variables are being set but do not know enough to be sure.
What is the problem and is there an easy way around it?

Any help on this matter greatly appreciated.

Kind regards


Re: Session variables through frames - need help.

On Mon, 02 May 2005 22:58:21 +0100, Dave Smithz wrote:

Quoted text here. Click to load it

I've played around with frames only a little, but am also using some
iframes and I think the situation is the same.

In a no-frames situation, you have your session_start() call somewhere on
each page's script, and since your browser sends the same session ID, your
session is continued, and your session variables are remembered, from page
request to page request.

In a frames situation, you can have the same thing happen. Each frame
calls its separate source URL. In this case, each of these source URL's
have to be php scripts, and they all have to call session_start()
somewhere at the top of the script.

Since your browser works in the same browser window when loading up
various frames, the browser sends the same session key, so if you do the
above, your session variables are accessible from all frames.

You can also have one frame read in a form on submit, collect the posted
values from $_POST and put them into $_SESSION, so that the posted form
values will be available to other frames.

Hope that helps.

Site Timeline