JavaScript includes and php variables replacement

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
lovasco
Forum Newbie
Posts: 15
Joined: Fri May 17, 2002 4:25 am
Location: Milan - Italy

JavaScript includes and php variables replacement

Post by lovasco »

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.
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

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:

Code: Select all

session_register("varname");
$varname = "ham";
// next page
echo $varname;
New way for registering:

Code: Select all

$_SESSION&#1111;'varname'] = "ham";
// next page
echo $_SESSION&#1111;'varname'];
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.
Post Reply