Frames, menus and sessions - almost works!

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
jim_73_mk1
Forum Newbie
Posts: 15
Joined: Mon Nov 24, 2003 9:42 pm
Contact:

Frames, menus and sessions - almost works!

Post by jim_73_mk1 »

I am building a website based on two frames, topFrame and mainFrame. The topFrame contains the menu which is a simple table with links. I want to disable the link after the user clicks on it. Clicking on a subsequent menu link would disable the current link (the one just clicked) and also enable the previously disabled link. I've done this very thing in a simple one page format with the same table type structure and it works nicely although the menu scrolls off the page, hence the reason I want to use frames on this site.

Now, to combat the nastiness of frames I thought I would try using session variables to track what page the user was on. This works - sort of. The problem is that the enabling and disabling of the links doesn't happen unless I refresh the page.

I believe my problem has to do with timing. The menu being in topFrame is loading first and the session variable it needs gets set when the mainFrame is loaded. The menu displays properly when refreshed (or the same link is clicked again) because the session variable is set.

Must I put the menu at the bottom? Is there a way to force the mainFrame to load first? Is there another way to do this without using client side scripting?

Thanks for your help!
Jim

Here are some code snippits:

This builds the menu:

Code: Select all

function menu() {
  ?>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100">
          <img src="images/logo2.jpg" border="0" height="100" width="92" alt="Logo">
        </td>
        <td width="*" align="center" valign="top">
          <table border="0" cellspacing="2" cellpadding="2">
            <tr>
              <?php
                $links = array(
                  'index.html', 'Newsletter', 'index.html', 'Calendar', 
                  'index.html', 'Education', 'index.html', 'Resources', 
                  'main.php', 'Home', 'index.html', 'Membership', 
                  'index.html', 'Gallery', 'about.php', 'About US',
                  'index.html', 'Contact Us', 'index.html', 'Login');
                $c = 0;
                while($c < count($links)) &#123;
                  if($links&#1111;$c+1] != $_SESSION&#1111;'page']) &#123;
                    echo '<td align="center">
                      <a href="' . $links&#1111;$c] . '" target="mainFrame"
                      onClick="parent.frames&#1111;''topFrame''].location.reload()">' 
                      . $links&#1111;$c+1] . '</a></td>';
                  &#125;else &#123;
                    echo '<td class="selected" align="center">' . 
                      $links&#1111;$c+1] . '</td>';
                  &#125;
                  $c = $c+2;
                  if($c == 10) echo '</tr><tr>';
                &#125;
              ?>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  <hr>
  <?php
&#125;
This is the header. I added some cache control because I thought it might be a caching issue:

Code: Select all

function output_html_header($title, $style) &#123;
  ?>
    <html>
    <head>
    <LINK HREF="../public_html/styles.css" TYPE="text/css"
      REL="stylesheet" TITLE="styles">
    <?php output_html_title($title); ?>
    <meta http-equiv="Content-Type" content="text/html;
      charset=iso-8859-1">
    <meta http-equiv="Cache-Control" Content="no-cache">
    <meta http-equiv="Pragma" Content="no-cache">
    <meta http-equiv="Expires" Content="0">
    </head>
    <body class="<?php echo $style; ?>">
  <?php
&#125;
This is a sample of the beginning of each content page:

Code: Select all

<?php 
  session_start(); // for session support
  $_SESSION&#1111;'page'] = 'About Us'; // this is a marker for the page
  include_once('../includes/includes.php');
  output_html_header('Welcome to the Alliance', 'body');
?>
Post Reply