Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Since we're updating ... deprecated session and ereg solutions


stickypod

Recommended Posts

I recently upgraded to PHP 5.3.8 and as all of you are finding out, this does create some problems with the deprecated code you currently have in your store. Here's a summary of how I solved this problem:

 

First, do not turn off the error codes. That's the only way you're going to find the problems.

Next, you must change your sessions.php on both the catalog and admin side: /catalog/includes/functions/sessions.php and /catalog/admin/includes/functions/sessions.php

 

REPLACE THIS: (around line 70)

 

 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);
 }

 

WITH THIS:

 

// check PHP version and use appropriate session variables - authored by ecartz (Matt)
 function tep_session_register($variable) {
	global $session_started;

	if ($session_started == true) {
	  if (PHP_VERSION < 4.3) {
			return session_register($variable);
	  } else {
			if (isset($GLOBALS[$variable])) {
			  $_SESSION[$variable] =& $GLOBALS[$variable];
			} else {
			  $_SESSION[$variable] = null;
			}
	  }
	}

	return false;
 }

 function tep_session_is_registered($variable) {
	if (PHP_VERSION < 4.3) {
	  return session_is_registered($variable);
	} else {
	  return isset($_SESSION) && array_key_exists($variable, $_SESSION);
	}
 }

 function tep_session_unregister($variable) {
	if (PHP_VERSION < 4.3) {
	  return session_unregister($variable);
	} else {
	  unset($_SESSION[$variable]);
	}
 }

 

Once you have this complete, you need to change all your ereg functions to the new preg functions for 5.3. I used the following tutorial authored by Mark Evans:

 

https://github.com/o...def4f2c9f94b0b7

 

Once this was complete, you must update your usps.php files for shipping. catalog/includes/modules/shipping/usps.php

 

In this file, you will find many ereg functions that need to be changed to preg_match functions. They look like this:

 

OLD if (ereg('<Error>', $response[0])) {

NEW if (preg_match('/<Error>/', $response[0])) {

 

OLD $number = ereg('<Number>(.*)</Number>', $response[0], $regs);

NEW $number = preg_match('|<Number>(.*)</Number>|', $response[0], $regs);

 

Note the | instead of the / in some of the lines. In the 2nd example, you'll see this and that's because the forward slash interferes with the original code. So you must use a pipe ( | ) character for these lines.

 

Finally, once you have this complete, you'll get your USPS shipping module back and you should be done (FedEx was unaffected and I don't use UPS). If you did not turn off error messages, you will not see any errors.

 

I run Dynamo Effects One Page Checkout and everything works great after all the above is complete.

 

Now I'm updated to PHP 5.3.8 and I can start upgrading to osC 3.0 and still run my old store.

 

I hope this helps others and I take no credit as I did not write any of the code.

Anyone can buy a camera... it's what you do with it that counts!

Sticky Pod

www.stickypod.com

Link to comment
Share on other sites

OLD if (eregi('<Error>', $response[0])) {

NEW if (preg_match('/<Error>/i', $response[0])) {

 

OLD $number = eregi('<Number>(.*)</Number>', $response[0], $regs);

NEW $number = preg_match('|<Number>(.*)</Number>|i', $response[0], $regs);

 

In general, if / is in the pattern, you either choose a different delimiter | or #, or escape any / in the pattern with \ : <\/Number>. If the pattern is a variable, enclose it in quotation marks: "/$pattern/".

 

OLD $array = split('pattern', $string)

NEW $array = preg_split('/pattern/', $string)

 

etc.

Also see ereg_replace() and probably a few others.

Link to comment
Share on other sites

  • 4 weeks later...

I recently upgraded to PHP 5.3.8 and as all of you are finding out, this does create some problems with the deprecated code you currently have in your store. Here's a summary of how I solved this problem:

 

First, do not turn off the error codes. That's the only way you're going to find the problems.

Next, you must change your sessions.php on both the catalog and admin side: /catalog/includes/functions/sessions.php and /catalog/admin/includes/functions/sessions.php.......

 

Now I'm updated to PHP 5.3.8 and I can start upgrading to osC 3.0 and still run my old store.

 

I hope this helps others and I take no credit as I did not write any of the code.

 

 

THANK YOU!

Спасибо,

Landis.

 

p.s., I also needed this for the language.php

http://forums.oscomm...20#entry1613041

Link to comment
Share on other sites

  • 5 months later...

Thank You! This was very helpful. After all changes however, I was having a problem with 'selected_box' variable in admin area not being recorded into the session. I removed the "if ($session_started == true) " condition from inside function tep_session_register and it resolved the issue. Hope this will not create other unseen issues. Thanks again!

Link to comment
Share on other sites

  • 4 months later...

Hi - thanks for the info on how to update the functions for osCommerce. I've updated my code but I'm having an issue when it comes to logging in as an admin to the admin area.

 

When I attempt to login, it is bouncing me back to the login page, as though it's not saving the login sessions correctly. I know the database query is working as I can put in an incorrect login and it will tell me it's incorrect. The thing I find strange is that I can go to the customer login page (login.php not via admin obviously) and login to the site fine, it's just logging in via the admin page (/admin/login.php) that I can't do.

 

Can you help?

Link to comment
Share on other sites

@@mthiner

 

Truncate the action_recorder, administrators and sessions tables. Then, clear your browser cookies and cache. Then, log back into the admin area. You will see there are NO administrators and you will be prompted to create a new administrator. Do that and then log into your admin area.

 

 

 

Chris

Link to comment
Share on other sites

  • 2 months later...

I have a problem with my shop. Costumers can't buy in market and they can't login with their account. Oscommerce is RC1 and problem has shown up after upgrading PHP 5.3.

 

I used the following tutorial authored by Mark Evans but I don't know how to change /catalog/includes/functions/sessions.php and /catalog/admin/includes/functions/sessions.php.

My sessions.php is

 

function tep_session_start() {
// >>> BEGIN REGISTER_GLOBALS
   $success = session_start();
   // Work-around to allow disabling of register_globals - map all defined
   // session variables
   if ($success && count($_SESSION))
   {
  $session_keys = array_keys($_SESSION);
  foreach($session_keys as $variable)
  {
    link_session_variable($variable, true);
  }
   }
   return $success;
// <<< END REGISTER_GLOBALS
 }
 function tep_session_register($variable) {
// >>> BEGIN REGISTER_GLOBALS
// -skip-   return session_register($variable);
   // Work-around to allow disabling of register_globals - map session variable
   link_session_variable($variable, true);
   return true;
// <<< END SESSION_REGISTER
 }
 function tep_session_is_registered($variable) {
// >>> BEGIN REGISTER_GLOBALS
//    return session_is_registered($variable);
   return isset($_SESSION[$variable]);
// <<< END REGISTER_GLOBALS
 }
 function tep_session_unregister($variable) {
// >>> BEGIN REGISTER_GLOBALS
   // Work-around to allow disabling of register_globals - unmap session variable
   link_session_variable($variable, false);
   unset($_SESSION[$variable]);
//  return session_unregister($variable);
   return true;
// <<< END REGISTER_GLOBALS
 }

// >>> BEGIN REGISTER_GLOBALS
 // Work-around function to allow disabling of register_globals in php.ini
 // This is pretty crude but it works. What it does is map session variables to
 // a corresponding global variable.
 // In this way, the main application code can continue to use the existing
 // global varaible names but they are actually redirected to the real session
 // variables
 //
 // If the global variable is already set with a value at the time of the mapping
 // then it is copied over to the real session variable before being mapped back
 // again
 //
 // Parameters:
 // var_name - Name of session variable
 // map - true = map variable, false = unmap varaible
 //
 // Returns:
 // None
 function link_session_variable($var_name, $map)
 {
   if ($map)
   {
  // Map global to session variable. If the global variable is already set to some value
  // then its value overwrites the session variable. I **THINK** this is correct behaviour
  if (isset($GLOBALS[$var_name]))
  {
    $_SESSION[$var_name] = $GLOBALS[$var_name];
  }
  $GLOBALS[$var_name] =& $_SESSION[$var_name];
   }
   else
   {
  // Unmap global from session variable. Note that the global variable keeps the value of
  // the session variable. This should be unnecessary but it reflects the same behaviour
  // as having register_globals enabled, so in case the OSC code assumes this behaviour,
  // it is reproduced here
  $nothing;
  $GLOBALS[$var_name] =& $nothing;
  unset($GLOBALS[$var_name]);
  $GLOBALS[$var_name] = $_SESSION[$var_name];
   }
 }
// <<< END REGISTER_GLOBALS
 function tep_session_id($sessid = '') {
   if ($sessid != '') {
  return session_id($sessid);
   } else {
  return session_id();
   }
 }
 function tep_session_name($name = '') {
   if ($name != '') {
  return session_name($name);
   } else {
  return session_name();
   }
 }
 function tep_session_close() {
// >>> BEGIN REGISTER_GLOBALS
   // Work-around to allow disabling of register_gloabls - unmap all defined
   // session variables
   if (count($_SESSION))
   {
  $session_keys = array_keys($_SESSION);
  foreach($session_keys as $variable)
  {
    link_session_variable($variable, false);
  }
   }
// <<< END REGISTER_GLOBALS
   if (function_exists('session_close')) {
  session_close();
   }
 }
 function tep_session_destroy() {
// >>> BEGIN REGISTER_GLOBALS
   // Work-around to allow disabling of register_gloabls - unmap all defined
   // session variables
   if (count($_SESSION))
   {
  $session_keys = array_keys($_SESSION);
  foreach($session_keys as $variable)
  {
    link_session_variable($variable, false);
    unset($_SESSION[$variable]);
  }
   }
// <<< END REGISTER_GLOBALS
   return session_destroy();
 }
 function tep_session_save_path($path = '') {
   if ($path != '') {
  return session_save_path($path);
   } else {
  return session_save_path();
   }
 }

 

This is an error when costumers tries to login

 

Deprecated: Function ereg_replace() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 57
Deprecated: Function ereg_replace() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 57
Warning: Cannot modify header information - headers already sent by (output started at /home/shoop/public_html/includes/functions/general.php:57) in /home/shoop/public_html/includes/functions/general.php on line 29

 

and this is an error when customer tries to buy

 

Deprecated: Function ereg() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 1044
Deprecated: Function ereg() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 1044
Deprecated: Function ereg() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 1044
Deprecated: Function ereg() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 1044
Deprecated: Function ereg() is deprecated in /home/shoop/public_html/includes/functions/general.php on line 1044
Warning: Cannot modify header information - headers already sent by (output started at /home/shoop/public_html/includes/functions/general.php:1044) in /home/shoop/public_html/includes/functions/general.php on line 29

 

Thank you in advance, best regarads.

Link to comment
Share on other sites

I know updating osCommerce would probably correct the issue, but I don't have knowledge and experience for that update. My shop has over one thousand registered users and I don't want to risk existing database.

 

I already solved some other problems without upgrading (language error, system's timezone), so I was hoping to find alternative for registration too. No luck so far.

 

My "old" shop :-( (www. gaz.hr) as you can see, everything is working except its basic function.

Link to comment
Share on other sites

You need to convert the two ereg functions mentioned in the errors with their equivalent preg functions. Examples are spread throughout the forums and on the web. Or someone would probably provide them here if you posted the code.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

I tried with preg function earlier, then I get no error message but problem is still the same.

 

In application_top.php I don use

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

Link to comment
Share on other sites

Ok, I'll try to be more precise. Web shop worked fine on PHP 5.2. Until my hoster upgraded it on PHP 5.3.19.

 

I have done all changes as descibed in first post (stickypod) here including changes from Mark Evans tutorial.

 

The changes I made are in following files:

 

catalog/includes/functions/sessions.php

catalog/admin/includes/functions/sessions.php

catalog/admin/backup.php

catalog/admin/cache.php

catalog/admin/configuration.php

catalog/admin/includes/classes/language.php

catalog/admin/includes/classes/phplot.php

catalog/admin/includes/classes/sessions.php

catalog/admin/includes/functions/compatibility.php

catalog/admin/includes/functions/general.php

catalog/admin/includes/functions/html_graphs.php

catalog/admin/includes/functions/validations.php

catalog/admin/modules.php

catalog/admin/server_info.php

catalog/admin/whos_online.php

catalog/advanced_search_result.php

catalog/includes/application_top.php

catalog/includes/classes/cc_validation.php

catalog/includes/classes/http_client.php

catalog/includes/classes/language.php

catalog/includes/classes/sessions.php

catalog/includes/functions/compatibility.php

catalog/includes/functions/general.php

catalog/includes/functions/validations.php

catalog/index.php

catalog/includes/modules/shipping/usps.php

 

So there is too many lines of code to post. All lines of code I changed are the similar as in link here.

Lines coloured in red are before and green ones are after change.

 

Funny fact is that I can registrate as a new costumer but logging in with same account failes.(redirects to home page). When I try to fill my card, it pops the message "Your card is empty".

Link to comment
Share on other sites

Ok, I'll try to be more precise. Web shop worked fine on PHP 5.2. Until my hoster upgraded it on PHP 5.3.19.

 

I have done all changes as descibed in first post (stickypod) here including changes from Mark Evans tutorial.

 

So there is too many lines of code to post. All lines of code I changed are the similar as in link here.

Lines coloured in red are before and green ones are after change.

 

Funny fact is that I can registrate as a new costumer but logging in with same account failes.(redirects to home page). When I try to fill my card, it pops the message "Your card is empty".

You're missing the point. When you see a failure, like the one you previously posted (general.php on line 57), it shows the file and the line number in that file where the error occurred. If you would post the code at that location, the problem will probably be fixed shortly after.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

If you picked the low hanging fruit (ereg, etc.) but did nothing about the changes to session functions, or changed them incorrectly, that could be tripping you up. Did you follow the osC PHP 5.3 patch to also fix session handling?

Link to comment
Share on other sites

Post the code from the two lines that are giving the errors

 

/home/shoop/public_html/includes/functions/general.php on line 57

 

and

 

/home/shoop/public_html/includes/functions/general.php on line 1044

 

Someone will then help with the correct code to remove the errors.

 

If you have followed the 5.3 upgrade path you should have altered this file, and may not have done so correctly as there are many changes to be made to this file.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

I'm sorry I didn't make myself clear.

Four days ago, when I wrote my first post I haven't done all changes tutorial recommendes. Then I had an error which I describe at the bottom of post.

 

In meanwhile I completed tutorial to upgrade PHP including all necessary changes. And now I don't get any error message, but problem with login and buying are a still present. So the point is, I can't show you code lines that are giving the errors, because I dont get a notice.

 

I point out that in my /includes/application_top.php and admin/includes/application_top.php file in line 17 I use code

 

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

 

So I let aplication to notify me for occured errors.

 

If you want you can try to test my web and registrate as a new user (www . gaz.hr), and you will get an email for successfully registration. And then when you try to login as the same user, it failes, and it redirectes you to home page. With no error message.

 

And when you try to fill your cart it gives you not logical notice that your cart is empty.

 

Yestarday I started with another upgrade of osC from 2.2 Milestone 2 to 2.2 RC2a . So far I completed first half of changes (1-40) but problem is still present.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...