ok well here what im trying to do: I have a 2 frame page...1 frame being a top menu bar and the other the website body. on every page i register a session variable called $instructions with a text string attached of somekind. now i want to print this string in the menu frame. but the problem is that the text on the menu frame
(as the session variable $instructions changes) wont change unless i reload the whole browser window. then it will change and wont change again untili reload the window again. i was hoping someone could help me write a code that will change this text on the menu bar instantly when the session variable changes sending messages to the user in the top menu bar. or a code which will reload the frame window(if thats posible) upon a change to this session variable $instructions. i was tring to use the header function here to reload the page...with no luck....
heres he code to my menu bar , and please dont laugh im just starting out.
<?
session_start();

$temp = $instructions; / i was hoping this would create a copy of $instructions and when the original changed it wouldnt match/

if ($temp != $instructions)
{
header("location:menu.php"); /also tried $PHP_SELF to redirect the frame to the same page trying to reload the frame/
exit;
}
else
{
$now = $instructions; /the string in $now prints out below but wont change unless i reload the browser/
}
?>
<html>
<head>
<base target="main"
</head>
<body bgcolor="black" text="white" link="white" alink="yellow" vlink="white">

<table border="0" bordercolor="white" width="100%" cellpadding="0" cellspacing="0"style="border-collapse: collapse">
<td height="10%">

<table border="0" bordercolor=yellow cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr align="center" valign="middle">
<td>
<h3><a href="front.php" style="text-decoration:none"> Home </a></h3>
<td>
<h3><a href="maccount.php" style="text-decoration:none"> Make Account </a></h3>
<td>
<h3>
<a href="search.php" style="text-decoration:none"> Seach Our Database </h3></a>
</table>

</td>
<td align="center">
<?php
print "$now";
?></td>
</table>
</body>
</html>

    {Personal opinion}DON'T USE FRAMES - THEY'RE MORE TROUBLE THAN THEY'RE WORTH

    Doing what you are trying to do you need to reload the menu frame constantly (every time you change content of the main frame), therefore defying the only point in using frames.

    Just create your menu section with a function (or a class) and call it at the head of every page.

    Hope this helps :rolleyes:

      you mean put this code in a file and incude it at the top of every page?????after the </head> or before cause you said in the head of every page. why would it need to be a function????wouldnt i just make a file and then use the
      include("new_file_i_just_made.php")????????

      The reason to use frames would be so the menu bar would stay visable at the top while the rest of the page scrolls with content. isn't it possible to make the top frame reload if the session variable changes???? thats what i really need to know. not advice on how to avoid this task completely, thanks for your help, but i am trying to learn php and it would be nice to know how to make a page reload if a variable changes. im sure its just some easy 2 or 3 line code that i dont know that might use javascript or some html reload function. also what kinda code would sense the variable change??would the one i made in the page work if i could just get the page to reload?
      hopefully someone could help out ,
      thanks

        i'm pretty green but ...

        i'm trying to get my head around this .... you want to reload the menu frame when one of the 'main' pages requires that a new set of instructions is displayed in the menu frame.

        This only happens when "main.php" is loading and you want a simle way of opening a url on the fly that would:

        href="menu.php" .. for ... target="menu"

        is this right ?

        1. if so can do this with javascript
          -somthing like ..

        <script>
        top.frames[1].location.href=self.location
        </script>

        1. BUT at this stage, main.php is loading and determines that menu.php needs to be reloaded. What is wrong with reloading from scratch...not so elegant but simple and should be just as quick?

        2. i'm sorry i don't like frames either - but i do use em sometimes ..?

        be interested in seeing how you go with this.

        Good luck

          thanks for your response-im pretty green too at the moment🙂
          do you know the javascript code to reload the current page???
          well heres what im trying to do the idea is pretty simple.
          i have a menu.php frame at the top of the window with a few links to move around the main frame and also a tag in there thats prints a session variable that contains a string this is called $instructions. now when your moving around the main page i might have an IF statement that will set the $instructions to a new message. if the user does something for instance.
          ---------in the main frame
          if (isset($t1))
          {
          $instructions = "Thanks for submitting t1";

          }

          i want this new message to appear at the menu frame. and change as the session variable $instructions changes.
          obviously the reason for doing this would be so the user see's the message at the top frame nomatter where he/she's at. they way i have it set up now the message will switch if i reload the browser window, now all i have to do is figure out how to reload the browser or preferably the menu frame window automatically whenever the variable $instructions changes.

          hope this questions understandable...
          jacob

            hi there again

            javascript is client side and allows you to do things on the basis of user interaction. php is server side so once you've put together a page then you don't really have the opportunity to implement logic.

            so you can do all sorts of good stuff with the user with javascript but how can you change the session variables when they are back on the server??

            (you can only get to the session information when you ask for something new from the server because this info is waiting there for you to request something new and supply a valid session id.) So you can't change session information without loading a new page

            but you can use javascript to load the menu.php page. use an onClick = "refreshmenu()" , or whatever user event you
            want, to trigger the update. (you can also use various means to store variables for more complex user interaction)

            <script>
            function refreshmenu {
            
            //in here you can do stuff like use a variable (eg. hidden form variable) to hold the info you want to send then set a url with variable to update ...
            
            var infotype = document.my_formname.my_hiddenfield.value
            //something like this ... i don't use frames much 
            var myURL = "menu.php?info=" + infotype
            top.frames[1].location.href=myURL
            }
            </script>
            

            note: the status bar might be a good place for the types of things you are displaying.

              the statis bar is a good idea but i want to get this thing working because i wanna figure this out...it would have to be a php code that senses the variable change but then im thinking it would have to print a javascript code to the browser to reload the page....i know javascript wont sense the variable change....so do any of you guys know how to make a code that does something when a variable changes??? it would probably be an IF statent that does
              IF(variable changes)
              {
              print "<script> reload </script>"; /ill figure out the javacript later i just need to know what kinda arument to write in the if statment where it says (variable changes) that senses if the session variable changes/
              }
              well hopefully some can figure this out because i really want to know....hey if we're all newbies to php here we need to be figuring weird stuff like this out to acually learn the language & programming...how are we gonna learn if when we run into something we cant do and we just decide to do something else because we already know it..sure i can just forget the thing and just use a table at the top of the browser to display the menu....how would you learn anything though...i already know how to do that, i already know how to write something to the status bar....what i need to know is how to sense a session variable change and make a code react to it by reloading the page???

                i agree with most of what you are saying but some things just aren't meant to be. The

                the session variable is on the server and cannot be accessed or changed by the $REMOTE_HOST once the page is returned by the server!! (except by requesting a new page)

                PHP is interpretted on the server before the HTML is sent to the $REMOTE_HOST. The $REMOTE_HOST gets HTML & javascript (no php here!! and no way to process it - your browser does not know anything about php!)

                so EVERYTHING! at the $REMOTE_HOST is HTML and javascript. ---

                In your example:

                ---------in the main frame
                if (isset($t1))
                {
                $instructions = "Thanks for submitting t1";
                }
                ----------
                //i want this new message to appear at the menu frame. and change as the session variable $instructions changes.
                

                i can't see why the code example below doesn't work for you but you don't have many options here - please explain!
                (ie. you can update the menu.php with the instructions and it gives you access to the session data)

                  Write a Reply...