Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

osC PHP code inside javascript: problem


yocompia

Recommended Posts

i'm using a javascript menu in conjunction with STS v4.1 and would like to have a button on the menu that changes from "Log In" to "Log Off" once a user has logged in. to do this, i've tried to use PHP code from osC to check if the customer is logged in. the code i've tried to use comes from line 68 of catalog/includes/header.php:

	<td align="right" class="headerNavigation"><?php if (tep_session_is_registered('customer_id')) { ?><a href="<?php echo tep_href_link(FILENAME_LOGOFF, '', 'SSL'); ?>" class="headerNavigation"><?php echo HEADER_TITLE_LOGOFF; ?></a>  |  <?php } ?><a href="<?php echo tep_href_link(FILENAME_ACCOUNT, '', 'SSL'); ?>" class="headerNavigation"><?php echo HEADER_TITLE_MY_ACCOUNT; ?></a>  |  <a href="<?php echo tep_href_link(FILENAME_SHOPPING_CART); ?>" class="headerNavigation"><?php echo HEADER_TITLE_CART_CONTENTS; ?></a>  |  <a href="<?php echo tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>" class="headerNavigation"><?php echo HEADER_TITLE_CHECKOUT; ?></a>   </td>

this code should display HEADER_TITLE_LOGOFF if tep_session_is_registered('customer_id') returns true. since tep_session_is_registered is defined as

  function tep_session_is_registered($variable) {
// >>> BEGIN REGISTER_GLOBALS
//	return session_is_registered($variable);
return isset($_SESSION[$variable]);
// <<< END REGISTER_GLOBALS
 }

in catalog/includes/functions/session.php on line 133, i figured i could put the following code inside my javascript menu (which is linked as PHP) to check whether to display "Log Off" or "Log In":

aI("<?php if (isset($_SESSION['customer_id'])) { echo "text=Log Off;url=/catalog/logoff.php\");"; } else { echo "text=Log In;url=/catalog/login.php;\");\n"; } ?>

however, this does not work correctly, it only displays "Log In", from which i assume this particular superglobal isn't set.

 

any suggestions on how to achieve what i'm aiming for? i might be able to insert the js menu in the $cataloglogo part that STS includes. thx for reading.

Link to comment
Share on other sites

Found it... pretty simple actually... the below will add a log-out image (with roll-over) IF the person IS logged in... if they are not it won't show... hope this helps

 

<?php if (tep_session_is_registered('customer_id')) { ?><a href="/logoff.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Logoff','','/includes/sts_templates/tmpl/images/Logoff_over.jpg',1)"><img src="/includes/sts_templates/tmpl/images/Logoff.jpg" alt="Logoff" name="Logoff" width="52" height="28" border="0"></a><?php } ?>

Link to comment
Share on other sites

which template file?

 

this doesn't exactly answer my question since i know that the tep_session_is_registered function works fine for determining whether someone is logged in inside existing osC PHP files. i guess i need to have the menu HTML embedded in the osC code to have it display right.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...