Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

SESSIONS AND DHTML


spieh

Recommended Posts

Posted

I have a javascript which generates a DHTML menu I got from the contribs section.

 

You preset the contents of the menu in your file to tell it the caption and link of each cell of the menu to via the cPath variable (i.e.)

 

var MENU_ITEMS = ["Category4", "index.php?cPath=4"];

 

then the rest of the script handles the positioning and mousevents and CSS styles for the menu cells.

 

The problem is that the menu doesn't use the SESSION ID so if the user logs in and adds an item to the cart and then uses the menu to choose another category, the SESSION ID is not passed since the menu only uses the default cPath number.

 

This causes the session to be lost and requires the user to login again.

 

I thought I would try using the tep_href_link() function to keep the session in tact such as...

 

var MENU_ITEMS = ["Category4", tep_href_link("index.php", 4)];

 

But this does not work because javascript is executed on client side and PHP is executed on servside so it cannot execute any of oscommerce's tep_functions from the client side once the page has been generated without submitting a new connection to the server to call the functions again.

 

Does anyone have any suggesstions as how to preserve the sessionID in my example.

 

-Dave

Posted

I have a similar problem... I need to make certain categories available from a dropdown menu, but I'm not realy a programmer.

 

Jscript code:

var menu1=new Array()
menu1[0]='<a href="/catalog.php?manufacturers_id=12">STYLANDIA</a>'
menu1[1]='<a href="/catalog.php?manufacturers_id=13">NGS</a>'
menu1[3]='<a href="/catalog.php?manufacturers_id=14">MONRAY</a>'
....

 

Anyway... I need this but with Session ID & I have to release a site on friday :(

Posted
I have a similar problem... I need to make certain categories available from a dropdown menu, but I'm not realy a programmer.

 

Jscript code:

var menu1=new Array()
menu1[0]='<a href="/catalog.php?manufacturers_id=12">STYLANDIA</a>'
menu1[1]='<a href="/catalog.php?manufacturers_id=13">NGS</a>'
menu1[3]='<a href="/catalog.php?manufacturers_id=14">MONRAY</a>'
....

 

Anyway... I need this but with Session ID & I have to release a site on friday :(

 

 

only way is to generate the script using php.

Treasurer MFC

Posted

OK so this contrib I'm using has 3 files to make the menu.

 

<script language="JavaScript" src="menu.js"></script>

<script language="JavaScript" src="menu_items.js"></script>

<script language="JavaScript" src="menu_tpl.js"></script>

<script language="JavaScript">

<!--

new menu (MENU_ITEMS, MENU_POS, MENU_STYLES);

//->

</script>

 

The menu.js is the file which actually builds the menu.

The menu_tpl.js contains the positioning data and css styles for mouseevents.

The menu_items.js contains static information for the name of each cell of the menu and the link associated with it which is nothing more than an array.

 

example of file menu_items.js

 

var MENU_ITEMS =[
 ["HOME", "index.php",
 ["My Account", "account.php"],
 ["Shipping & Returns", "shipping.php"],
 ["Privacy Notice", "privacy.php"],
 ["Conditions 0f Use", "conditions.php"],
 ["Contact Us", "contact_us.php"]
],
["ProductX", "index.php?cPath=21",
 ["SubcategoryA", "index.php?cPath=21_28"],
 ["SubcategoryB", "index.php?cPath=21_4"],
 ["SubcategoryC", "index.php?cPath=21_29"],
 ["SubcategoryD", "index.php?cPath=21_16"]
];

 

so when the new_menu function is called it just uses the values of this array to generate static cells of the menu.

 

So rewriting the menu_items file instead of being a .js file to be a .php file.

 

<?php
$sessID = "";
if(!session_id())
{
//do nothing since no session has been started yet
}
else
{
  $sessID = "osCsid=" . session_id();
}
//generate javascript using php echo 
echo "<script language=\"JavaScript\">\n";
echo "var MENU_ITEMS =[\n";
echo "                                [\"HOME\", \"index.php?{$sessID}\",\n";
echo "                                [\"My Account\", \"account.php?{$sessID}\"],\n";
echo "                                [\"Shipping\", \"shipping.php?{$sessID}\"],\n";
echo "                                [\"Contact Us\", \"contact_us.php?{$sessID}\"]\n";
echo "                              ].\n";
echo "                            [\"ProductX\", \"index.php?cPatch=21\&{$sessID}\",\n";
echo "                                [\"SubcategoryA\", \"index.php?cPatch=21_28\&{$sessID}\"]\n";
echo "                              ];\n";
echo "</script>\n";
?>

 

so then replace the line in the original file

<script language="JavaScript" src="menu_items.js"></script>

 

with require("menu_items.php");

 

this should work though I have not tested it yet but the logic seems sound.

 

If you see any errors please point them out.

 

-Dave

Posted

Use the tep_href_link() function to generate the URL's...

 

Bobby

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...