Mystery "Black Hole" consuming Sessions in Frames

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
PHPCold
Forum Newbie
Posts: 1
Joined: Fri Oct 29, 2004 3:19 am

Mystery "Black Hole" consuming Sessions in Frames

Post by PHPCold »

Hello,

I am attempting to assist someone in the development of their PHP-based webpage (although I know little about PHP my self). We are having a problem when it comes to using Frames and Sessions together in PHP. I have heard people suggest using tables instead of frames, but if this is so, how can you implement a navigation menu using only tables?

But to the problem...

There is a login page that directs the user to FrameSet.php (a frameset of 2 frames, each frame using a different page of course) page when he successfully logs in (and a session begins).

From there, the user may click on a link in the left frame(navigation) page, and it then loads that page into the right(content) page.

The session ID needs to be continued throughout all the pages, no matter where the user goes, but we are having trouble with this.

We have included the following code in ALL pages, including the FrameSet.php, the default pages for both frames, as well as the page that is loaded in the right(content) frame when the user clicks the link in the left(navigation) frame/page:

Code: Select all

session_start();
$id = $_SESSION['username'];
print ($id);
When we login with a test username, and the FrameSet.php loads both frames, it accurately displays the username we logged in with, on both frames. But when we click on a link on the left frame, and it loads the page, the session ID is lost (even though that loaded page has the same code as the other 3 pages (frameset, frame1, frame2)).

However, when we have the Login page direct to a non-frame page, the session is accurately continued, and continues to be continued as we go through links from that non-frame page to other non-frame pages.

Somehow the session ID is being lost when using frames, but we don't understand why since we have the session code in ALL pages.

Any suggestions/ideas?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

if your starting a session in more than 1 frame at a time, you might end up w/ more than 1 session. some data could be in session 1, some could be in session 2

i think it would work if you do NOT use sessions on the navigation menu

and im sure youve heard it before many times, but id recomend ditching frames.

as for how to get a navmenu on all pages, its really easy. just make sure the html thats output to them on every page contains the navmenu

you could do something as simple as include('navmenu.html');


you would be wise to make a site template, which defines the header, navmenu, and footer on all pages. then the only thing that changes is the content.

frames confuse people, try bookmarking a framed site, youll rarely get back to where you wanted. and for most users, that means frustration, and probably leaving the site totally.
Post Reply