Dear folks,
I have built a JavaScript-based DHTML drop-down menu (using the DHTML Menu Builder tool) and I have included the generated menu.js file at the beginning of each php page.
Now I would like to use the php session variables feature to share php variables across different pages. In order to do that, I need to append a ?<?=SID?> string at the end of each local link.
I changed the local URLs associated to each menu command accordingly, and generated a new version of menu.js.
However, when a web page is processed by php, the JavaScript menu.js include is not processed and therefore the SID constant is not replaced with its corresponding session id value.
Variables replacement works fine if JavaScript code is entered inline within the page (no include); however the menu.js file is very long and does not work properly when physically copied into each page.
Can you help me? Thanks.
JavaScript includes and php variables replacement
Moderator: General Moderators
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Don't worry about appending the SID at the end of the page or anything like that. All you have to do with sessions is put session_start(); at the top of every page, and session variables declared on one page will be accessable with all the others.
Old way of registering:
New way for registering:
It just depends on what version of PHP you are running. Try the new way first, and if that does not work, try the older way.
Old way of registering:
Code: Select all
session_register("varname");
$varname = "ham";
// next page
echo $varname;Code: Select all
$_SESSIONї'varname'] = "ham";
// next page
echo $_SESSIONї'varname'];