Registering, or Setting, a Value in OSCommerce.

Set a value on one page that is available for another page, or anywhere on the site:

  1. For example, to set the value of $myvar as ‘delorum ipsum’:
    <?php
      $myvar = 'delorum ipsum'; // give it a value here
      if ( ! tep_session_is_registered('myvar') ) {
        tep_session_register('myvar');
      }
    ?>
    

    In plain english this says:
    Make $myvar equal delorum ipsum, and if $myvar is not already registered or been set to equal delorum ipsum in the website, make it equal to delorum ipsum everywhere in the website.

  2. One the page you wish to carry that value to, simply echo the variable, ‘$myvar’ . In other words, below will print ‘delorum ipsum’.
    echo $myvar;
    
  3. When you no longer need the value, unregister it like so:
    tep_session_unregister('myvar');

This is done to allow information, that can come from the database or a form, to follow a customer as they navigate unpredictably through the shop. Here are some examples from OSCommerce:

  • Open login.php
    near the top you see these lines:

    tep_session_register('customer_id');
            tep_session_register('customer_default_address_id');
            tep_session_register('customer_first_name');
            tep_session_register('customer_country_id');
            tep_session_register('customer_zone_id');</code>
    </li>These are all values pulled from the database. 
    <li>Later on in catalog/checkout_shipping.php if the customer makes some comments on the form on that page, the comments get registered, and becomes the value of the variable  '$comments'.</li>
    tep_session_register('comments');
  • Open catalog/logoff.php: When the customer signs out, all this happens.
     tep_session_unregister('customer_id');
      tep_session_unregister('customer_default_address_id');
      tep_session_unregister('customer_first_name');
      tep_session_unregister('customer_country_id');
      tep_session_unregister('customer_zone_id');
      tep_session_unregister('comments');
  • This unregisters all the values that have been attached to those variables, because they are no longer needed.