How to get osCommerce 2.2 running on PHP 5.4?

rubo77 picture rubo77 · Oct 20, 2013 · Viewed 10k times · Source

I recently upgraded PHP to 5.4 and after adding some tweaks now the old osCommerce installation of a customer with lots of customisations is running again, but there is still a problem:

if you put an item in your cart the cart stays empty

How can I fix this?
Is there a certain php value I can set in php.ini so the session is working properly?


What I have tweaked so far:

Problem: all prices are 0 and there is no currency
Solution: adding !isset($currency) || in the paragraph `//
(see $currency not set in application_top under PHP 5.4 )

Problem: register_globals is REMOVED as of PHP 5.4.0
Solution: I simulated register_globals with this: https://serverfault.com/a/547285/128892

and I added this to includes/application_top.php:

// Bugfix PHP 5.4:
$HTTP_USER_AGENT=$_SERVER["HTTP_USER_AGENT"];
$HTTP_ACCEPT_LANGUAGE=$_SERVER["HTTP_ACCEPT_LANGUAGE"];
$HTTP_HOST=$_SERVER["HTTP_HOST"];
$SERVER_NAME=$_SERVER["SERVER_NAME"];
$PHP_SELF=$_SERVER['PHP_SELF'];
$HTTP_GET_VARS=$_GET;
$HTTP_POST_VARS=$_POST;
register_globals();

comment out this line:

#ini_get('register_globals') or exit('FATAL ERROR: register_globals is disabled in php.ini, please enable it!');

also I had to correct some removed functions in includes/functions/sessions.php: session_unregister() and session_is_registered()


Problem remaining: Items filled into the cart don't get added to the cart. seems like the session isn't known in the add_cart page.

Answer

Michael Bavin picture Michael Bavin · Sep 13, 2014

I've had the same problem. Found by comparing my 2.2ms2 code with rc2a version.

In application_top change

$cart->add_cart($_POST['products_id'], $cart->get_quantity(tep_get_uprid($_POST['products_id'], $_POST['id']))+$quantity, $_POST['id']);

to

$cart->add_cart($_POST['products_id'], $cart->get_quantity(tep_get_uprid($_POST['products_id'], $_POST['id']))+$_POST['quantity'], $_POST['id']);