How Can I Retain Session Id Outside Of osCommerce Catalog Directory?

Discussion in 'PHP' started by dublinguy, May 27, 2007.

  1. #1
    Hi,
    Using osCommerce, I am aware that tep_href_link makes sure the Session ID gets attached to the URL being called. However, it uses HTTP_SERVER . DIR_WS_HTTP_CATALOG (for NONSSL, anyway), meaning "catalog" must be part of the URL path.

    I want my customer to be able to back out to higher level pages, above the "catalog" directory -- and then return to their shopping when they are ready.

    I tried writing my own version of tep_href_link. I called it agp_tep_href_link and changed its signature to accept a boolean that tells whether it is at the "top" level, above "catalog". If, in "catalog/includes/header.php", I use this new function to go to a top-level page, it works fine: the page appears as expected, and the URL still contains the Session ID. HOWEVER, if I use this new function in my top-level page, I cannot figure out how to call the new method.

    Here is the modified agp_tep_href_link...
    // The HTML href link wrapper function written by AG Productions.// This version of the method allows the user to navigate to the top-level pages (above ../catalog) and still retain the session id. function agp_tep_href_link($topLevel = false, $page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) { global $request_type, $session_started, $SID; if (!tep_not_null($page)) { die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>'); } if ($connection == 'NONSSL') { if ($topLevel) { $link = HTTP_SERVER . '/'; } else { $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG; } } elseif ($connection == 'SSL') { if (ENABLE_SSL == true) { if ($topLevel) { $link = HTTPS_SERVER . '/'; } else { $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG; } } else { if ($topLevel) { $link = HTTP_SERVER . '/'; } else { $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG; } } } else { die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>'); } ... rest of function exactly as in tep_href_link...

    Here is use of it inside catalog/includes/header.php that works fine. Clicking the Home image button takes me to my top-level page, and the Session ID remains in the URL...
    <tr><td><a href="<?=agp_tep_href_link(true, 'index.php')?>" title="Home"><?=Tep_Image_Button('Home.gif')?></a><a href="<?=agp_tep_href_link(false, 'account.php')?>" title="My Account"><?=Tep_Image_Button('MyAccount.gif')?></a></td></tr>

    Here is just one of the many failed variations of php code I tried in my top-level menu. This only works if I'm on the Home page, and my other menu options do not appear at all..
    <!-- Home -->
    <?php if ($thisPage == "Home") {
    echo '<li class="menuItemSelected"><a title="Home">Home</a></li>';
    } else {
    echo '<li><a href="' . agp_tep_href_link(true, 'index.php') . '" title="Home">Home</a></li>';
    } ?>

    I will greatly appreciate any help. I'm sure the concept is sound. I think my problem lies with my inexperience in php. Ideally, someone already has an elegant solution for this: carrying the Session ID outside of the catalog.
    Cheers,
    Guy
     
    dublinguy, May 27, 2007 IP
  2. speda1

    speda1 Well-Known Member

    Messages:
    374
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    #2
    How about just writing it to a cookie?
     
    speda1, May 27, 2007 IP