Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

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

session_is_registered deprecated php 5.3 ereg functions

3 replies to this topic

#1 stickypod

  • Community Member
  • 84 posts
  • Real Name:Sticky Pod
  • Location:Englewood, Colorado

Posted 11 November 2011, 20:38

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.

Edited by stickypod, 11 November 2011, 20:42.

Anyone can buy a camera... it's what you do with it that counts!
Sticky Pod
www.stickypod.com

#2 MrPhil

  • Community Member
  • 3,294 posts
  • Real Name:Phil
  • Gender:Male

Posted 11 November 2011, 22:37

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.

#3 Landis

  • Community Member
  • 2 posts
  • Real Name:Landis Reed
  • Location:Michigan, U.S.A.

Posted 05 December 2011, 14:07

View Poststickypod, on 11 November 2011, 20:38, said:

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

Edited by Landis, 05 December 2011, 14:10.


#4 hiorti

  • Community Member
  • 1 posts
  • Real Name:Ed

Posted 06 May 2012, 00:33

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!

Edited by hiorti, 06 May 2012, 00:33.