Jump to content



Photo
- - - - -

PHP Deprecated: Function eregi()


This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1   wizb1t

wizb1t
  • Members
  • 4 posts

Posted 03 October 2011 - 21:48

I am running OSC 2.3.1, Centos 6.0 & PHP 5.3.8

The installer comes up, but when i input the database settings and press continue, the log fills with this and the installer never finished initializing the database:



PHP Deprecated: Function eregi() is deprecated in /home/oscommerce/install/includes/functions/database.php on line 98


line 98 says:


if ( (eregi('create', $next)) || (eregi('insert', $next)) || (eregi('drop t', $next)) ) {

#2   toyicebear

toyicebear
  • Community Sponsor
  • 6,412 posts

Posted 04 October 2011 - 01:23

Click me>>

#3   DunWeb

DunWeb

    The Censored One

  • Members
  • 13,084 posts

Posted 04 October 2011 - 01:25

I thought v2.3.1 was PHP 5.3 compatible ?

How can the installer contain deprecated ereg functions ? Maybe 2.4 will be better ? lol





Chris
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

#4   MrPhil

MrPhil
  • Members
  • 5,384 posts

Posted 04 October 2011 - 01:40

compatibility.php: find
return ereg('^[0-9]{1,50}.?[0-9]{0,50}$', $param);
and change to
return preg_match('/^[0-9]{1,50}.?[0-9]{0,50}$/', $param);

database.php: find
if ( (eregi('create', $next)) || (eregi('insert', $next)) || (eregi('drop t', $next)) ) {
and change to
if ( (preg_match('/create/i', $next)) || (preg_match('/insert/i', $next)) || (preg_match('/drop t/i', $next)) ) {

If there are more to fix, this has been discussed many times already. Actually, I'm kind of surprised... I thought osC 2.3 had been thoroughly cleaned up to make it PHP 5.3 compatible. I guess they missed something.

#5   softwarepro

softwarepro
  • Members
  • 3 posts

Posted 04 October 2011 - 03:33

Apparently ereg() and eregi() are not the only functions deprecated. A client told me her site was displaying multiple errors. I checked to see what version of PHP she was using and it was 5.3.6. The deprecated functions on her site were:

session_is_registered()
split()
ereg()
eregi()

and those were just the ones shown. I then checked several other clients websites and they all had similar errors though not all the same because most of the sites have been modified. Because of that, finding and fixing these errors will be more time consuming. I was very surprised to not see many people complaining about it yet here and also very surprised that there were no add-ons to fix the errors and no warnings from osCommerce posted. I was also surprised that the hosting company did not notify me they were going to upgrade all of the hosting accounts with the new version of PHP so I could see the many deprecated functions and changes and fix the osCommerce customers sites before the updates went into effect.

I would like to see osCommerce replace standard PHP and MySQL functions in their files with osCommerce "proxy" functions which are basically wrappers for the standard functions which would all be contained in a single include file. That way when PHP or MySQL deprecate something only the function in include file needs to be changed instead of hunting through numerous files to change multiple copies of the same functions. Just a thought.

#6   Taipo

Taipo
  • Members
  • 796 posts

Posted 04 October 2011 - 06:35

Most production servers have notices disabled so most users will not see the errors.
- Stop Oscommerce hacks dead in their tracks with osC_Sec (see discussion here)
- Another discussion about infected files ::here::
- A discussion on file permissions ::here::
- Site hacked? Should you upgrade or not, some thoughts ::here::
- Fix the admin login bypass exploit here
- Pareto Security: New security addon I am developing, a remake of osC_Sec in PHP 5 with a number of fixes
- BTC:1BkbNA1tK3q7ZRkCJj6f1ELK2A152eEtoW

#7   MrPhil

MrPhil
  • Members
  • 5,384 posts

Posted 04 October 2011 - 15:14

I would like to see osCommerce replace standard PHP and MySQL functions in their files with osCommerce "proxy" functions which are basically wrappers for the standard functions which would all be contained in a single include file. That way when PHP or MySQL deprecate something only the function in include file needs to be changed instead of hunting through numerous files to change multiple copies of the same functions. Just a thought.

The problem here is that PHP deliberately introduced incompatibilities in their language definition. I suppose it would be possible to put replacement functions into the compatibility.php layer, but 1) that would slow down osC quite a bit, and 2) it's not a simple matter. For example, for "eregi" you can't simply slap / and /i around the first argument (to preg_match) -- you need to check if / is used in the pattern, and either escape those uses, or choose another delimiter. In the long run, it's probably better to go through the code and properly fix it once and for all, than to keep jury-rigging patches like a compatibility layer (ditto for "long" array names, etc.). This would make osC incompatible with very old levels of PHP, but it's unreasonable to drag everyone else down supporting PHP 3.x or whatever.

#8   Mark Evans

Mark Evans

    Code Monkey Rockstar

  • Core Team
  • 2,521 posts

Posted 04 October 2011 - 15:37

See

https://github.com/o...e4b11ce6d71a1b3

Will be fixed in 2.3.2 and of course 2.4 Posted Image
Mark Evans
osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops)

---------------------------------------
Software is like sex: It's better when it's free. (Linus Torvalds)

#9   Mark Evans

Mark Evans

    Code Monkey Rockstar

  • Core Team
  • 2,521 posts

Posted 04 October 2011 - 16:27

I would like to see osCommerce replace standard PHP and MySQL functions in their files with osCommerce "proxy" functions which are basically wrappers for the standard functions which would all be contained in a single include file. That way when PHP or MySQL deprecate something only the function in include file needs to be changed instead of hunting through numerous files to change multiple copies of the same functions. Just a thought.


I would very much doubt we would do that as it would make maintenance a nightmare.
Mark Evans
osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops)

---------------------------------------
Software is like sex: It's better when it's free. (Linus Torvalds)

#10   wizb1t

wizb1t
  • Members
  • 4 posts

Posted 04 October 2011 - 17:52

ok, thanks for the fix /biggrin.png' class='bbc_emoticon' alt=':D' />

#11   alexandra66

alexandra66
  • Members
  • 1 posts

Posted 10 November 2011 - 10:34

hi. does anyone know how to fix these two function, I have tried everything I could and nothing seem to work.. This is a pop up contact form with email validation and

1) Deprecated: Function split() in red

function ValidateFileUploads()
{
$ret=true;
foreach($this->fileupload_fields as $upld_field)
{
$field_name = $upld_field["name"];

$valid_filetypes = $upld_field["file_types"];

if(!$this->IsFileUploaded($field_name))
{
continue;
}

and 2nd, Deprecated: Function eregi():

function validate_email($email)
{
return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);


Is there anyway to fix it?

#12   MrPhil

MrPhil
  • Members
  • 5,384 posts

Posted 11 November 2011 - 18:08

Where's the split call? Anyway, it should be changed to preg_split, and the first argument should get delimiters on it. E.g,.
$var = split('pattern', $string)
becomes
$var = preg_split('/pattern/', $string)
Note that if pattern is a variable rather than a string, you need to do: "/$pattern/". Also note that if the pattern has slashes in it (/), you need to either escape them: \/, or use a different delimiter (e.g., '#pattern#').

return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);
becomes
return preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email);