osCommerce: Running with Register Globals Off

There are several tutorials and contributions about how to run osCommerce with register_globals turned Off. However, all are very complicated, break compatibility with other contributions such as payments or delivery modules and are not compatible with both PHP4 and PHP5.
We made a very simple MOD, which allows you to run osCommerce on any PHP powered server with disabled Register Globals including PHP4 and PHP5. This MOD also works with register_globals = On, so if your host changes the configuration of the web server without your knowledge, osCommerce powered shopping cart will remain running.

Note: We’ve originally published this MOD on our old web site magic-seo-url.com as well as on osCommerce Community Add-Ons and later it became a part of osCommerce.

Magic SEO URLs for osCommerce

You need to apply this MOD especially, when you are getting one of the following messages:

Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory.

FATAL ERROR: register_globals is disabled in php.ini, please enable it!

To get resolve this problem, please follow these instructions:

Open:

catalog/includes/application_top.php

// start the timer for the page parse time log
  define('PAGE_PARSE_START_TIME', microtime());

Before, add:

// Register Globals MOD - http://www.magic-seo-url.com

  if (version_compare(phpversion(), "4.1.0", "<") === true) {
    $_GET &= $HTTP_GET_VARS;
    $_POST &= $HTTP_POST_VARS;
    $_SERVER &= $HTTP_SERVER_VARS;
    $_FILES &= $HTTP_POST_FILES;
    $_ENV &= $HTTP_ENV_VARS;
    if (isset($HTTP_COOKIE_VARS)) $_COOKIE &= $HTTP_COOKIE_VARS;
  }

  if (!ini_get("register_globals")) {
    extract($_GET, EXTR_SKIP);
    extract($_POST, EXTR_SKIP);
    extract($_COOKIE, EXTR_SKIP);
  }

Find:

// check if register_globals is enabled.
// since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
  if (function_exists('ini_get')) {
    ini_get('register_globals') or exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory.');
  }

Replace with:

// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
  /*if (function_exists('ini_get')) { // Register Globals MOD - http://www.magic-seo-url.com
    ini_get('register_globals') or exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory.');
  }*/

Find:

// set SID once, even if empty
  $SID = (defined('SID') ? SID : '');

Before, add:

// Register Globals MOD - http://www.magic-seo-url.com
  if (!ini_get("register_globals")) {
    if (version_compare(phpversion(), "4.1.0", "<") === true) {
      if (isset($HTTP_SESSION_VARS)) $_SESSION &= $HTTP_SESSION_VARS;
    }
    if(!empty($_SESSION)) extract($_SESSION, EXTR_SKIP);
  }

Open:

catalog/includes/functions/sessions.php

Find:

  function tep_session_register($variable) {
    global $session_started;

    if ($session_started == true) {
      return session_register($variable);
    } else {
      return false;
    }
  }

  function tep_session_is_registered($variable) {
    return session_is_registered($variable);
  }

  function tep_session_unregister($variable) {
    return session_unregister($variable);
  }

Replace with:

// Register Globals MOD - http://www.magic-seo-url.com
  function tep_session_register($variable) {
    global $session_started;
    if ($session_started == true) {
      $_SESSION[$variable] = '';
      return true;
    } else {
      return false;
    }
  }

  function tep_session_is_registered($variable) {
    if(isset($_SESSION[$variable])) {
      return true;
    } else {
      return false;
    }
  }

  function tep_session_unregister($variable) {
    unset($_SESSION[$variable]);
  }

Find:

  function tep_session_close() {
    if (PHP_VERSION >= '4.0.4') {
      return session_write_close();
    } elseif (function_exists('session_close')) {
      return session_close();
    }
  }

Replace with:

// Register Globals MOD - http://www.magic-seo-url.com
  function tep_session_close() {
    if(is_array($_SESSION)) {
      foreach($_SESSION as $key => $value) {
        global $$key;
        $_SESSION[$key] = $$key;
      }
    }
  }

catalog/admin/includes/application_top.php

Find:

// Start the clock for the page parse time log
  define('PAGE_PARSE_START_TIME', microtime());

Before, add:

  // Register Globals MOD - http://www.magic-seo-url.com
  if (version_compare(phpversion(), "4.1.0", "<") === true) {
    $_GET &= $HTTP_GET_VARS;
    $_POST &= $HTTP_POST_VARS;
    $_SERVER &= $HTTP_SERVER_VARS;
    $_FILES &= $HTTP_POST_FILES;
    $_ENV &= $HTTP_ENV_VARS;
    if (isset($HTTP_COOKIE_VARS)) $_COOKIE &= $HTTP_COOKIE_VARS;
  }

  if (!ini_get("register_globals")) {
    extract($_GET, EXTR_SKIP);
    extract($_POST, EXTR_SKIP);
    extract($_COOKIE, EXTR_SKIP);
  }

Find:

// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
  if (function_exists('ini_get')) {
    ini_get('register_globals') or exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory.');
  }

Replace with:

// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
  /*if (function_exists('ini_get')) { // Register Globals MOD - http://www.magic-seo-url.com
    ini_get('register_globals') or exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory.');
  }*/

Find:

// lets start our session
  tep_session_start();

After, add:

// Register Globals MOD - http://www.magic-seo-url.com
  if (!ini_get("register_globals")) {
    if (version_compare(phpversion(), "4.1.0", "<") === true) {
      if (isset($HTTP_SESSION_VARS)) $_SESSION &= $HTTP_SESSION_VARS;
    }
    if(!empty($_SESSION)) extract($_SESSION, EXTR_SKIP);
  }

Open:
catalog/admin/includes/functions/sessions.php

Find:

  function tep_session_register($variable) {
    return session_register($variable);
  }

  function tep_session_is_registered($variable) {
    return session_is_registered($variable);
  }

  function tep_session_unregister($variable) {
    return session_unregister($variable);
  } 

Replace with:

// Register Globals MOD - http://www.magic-seo-url.com
  function tep_session_register($variable) {
    $_SESSION[$variable] = '';
  }

  function tep_session_is_registered($variable) {
    if(isset($_SESSION[$variable])) {
      return true;
    } else {
      return false;
    }
  }

  function tep_session_unregister($variable) {
    unset($_SESSION[$variable]);
  }

Find:

  function tep_session_close() {
    if (function_exists('session_close')) {
      return session_close();
    }
  }

Replace with:

// Register Globals MOD - http://www.magic-seo-url.com
  function tep_session_close() {
    if(is_array($_SESSION)) {
      foreach($_SESSION as $key => $value) {
        global $$key;
        $_SESSION[$key] = $$key;
      }
    }
  }

Open:

catalog/install/includes/application.php

Find:

// Set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

After, add:

  // Register Globals MOD - http://www.magic-seo-url.com
  if (version_compare(phpversion(), "4.1.0", "<") === true) {
    $_GET &= $HTTP_GET_VARS;
    $_POST &= $HTTP_POST_VARS;
    $_SERVER &= $HTTP_SERVER_VARS;
    $_FILES &= $HTTP_POST_FILES;
    $_ENV &= $HTTP_ENV_VARS;
    if (isset($HTTP_COOKIE_VARS)) $_COOKIE &= $HTTP_COOKIE_VARS;
  }

  if (!ini_get("register_globals")) {
    extract($_GET, EXTR_SKIP);
    extract($_POST, EXTR_SKIP);
    extract($_COOKIE, EXTR_SKIP);
  }

Find:

// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
  if (function_exists('ini_get')) {
    ini_get('register_globals') or exit('FATAL ERROR: register_globals is disabled in php.ini, please enable it!');
  }

Replace with:

// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
  /*if (function_exists('ini_get')) {
    ini_get('register_globals') or exit('FATAL ERROR: register_globals is disabled in php.ini, please enable it!');
  }*/

Save an close all files and don’t forget to install our ultimate Magic SEO URLs for osCommerce module!

One thought on “osCommerce: Running with Register Globals Off

  1. i am extremely grateful to this workaround. myself, i would never have managed.
    it worked from start,
    i have however 2 small issues with the patched oscommerce
    # open baskets are shown in config/stats_unsold_carts.php but not for customer in /shopping_cart.php
    # randomly (Not always) address details, mostls street names in orders and confirmation mails vanish,
    data are however complete in database customers

    where should i look for a solution?
    important is basket shown to customer, with the other issue i can live
    i feel however that the 2 are connected and have to do with session variables

    regards, edgar

Leave a Reply

Your email address will not be published. Required fields are marked *

Cart  
(empty)

Cart Check out  »

Prices are tax inclusive.

The VAT rate for your country (US) * is 0,0 % because it is not a member of the European Union (EU).

* Please create an account if your country does not match.

Community feed
  • [WP Accelerator] How do I troubleshoot layout problems?
    Hi I am running the latest version of WordPress Accelerator (v1.2.06) and when I turn this on, the top navigation bar layout does not render properly: http://screencast.com/t/DKMtdA4szN If I...
    by markwoodroof
  • [Zen Cart] Change the default HTTP 404 page
    Hi there I cannot find how to change the page an incorrect category url gets defaulted to. I have Magic SEO installed and if I type in an incorrect category id to the url it sends me to the...
    by sthomasmccarthy
  • [BB2PS FULL] phpBB integration to PrestaShop module
    Hi! i finally reinstall my forum several days ago. How do i add the menu into the phpbb admin ? i've read the readme but i was not able to do it... thanks !
    by planetearcade
  • [Zen Cart] MSU with Sitemaps no longer works
    Hello, with Magic SEO URLs my SiteMap no longer works. When I generate the sitemap I get only 1 item: "http://www.inveostore.com/zencart-seo-module-v15-39" How can I make these two...
    by JacobBushnell
  • [phpBB3] Bookmark link to post
    I think there is a problem, no ? : http://www.vtt-alsace.fr/#p92627 instead of : http://www.vtt-alsace.fr/probleme-photo-4041#p92629
    by Binano
Join our support forum » Pre-Sales Questions »
Featured Testimonials

I installed the WordPress and WooCommerce Accelerator from Inveostore and it was really easy to configure - unlike some other caching plugins, it did not break the more complicated bits of my site and my PageSpeed score has gone from E to B even on a shared hosting plan. Luke was really helpful and the support response was very quick - I am...

Mark, the owner of Digital Marketing Works

Magic SEO URLs for osCommerce are amazing product, helps my site a lot with SEO. The biggest advance of Magic SEO URLs is excellent service support. I know what I'm talking about because I had already bought web software from about 10 different companies. Magic SEO URLs is the best one. Keep the quality of the product and service and...

Jacek, the owner of Agro-Modele.pl

More Testimonials »