Jump to content



Latest News: (loading..)

- - - - -

Function ereg_replace() is deprecated


  • Please log in to reply
136 replies to this topic

#81   Melinda Odom

Melinda Odom
  • Members
  • 1,212 posts
  • Real Name:Melinda Odom
  • Gender:Female
  • Location:United States

Posted 08 January 2010 - 12:11 AM

View Poststeve_s, on 07 January 2010 - 11:55 PM, said:

Hi replace code in admin/includes/functions/validation.php
with code below will also work on shop side to

<?php
/*
  $Id: validations.php 1739 2007-12-20 00:52:16Z hpdl $

  Open Source E-Commerce Solutions

  Copyright (c) 2003 osCommerce, http://www.oscommerce.com

  Released under the GNU General Public License
*/

  ////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Function	: tep_validate_email
  //
  // Arguments   : email   email address to be checked
  //
  // Return	  : true  - valid email address
  //			   false - invalid email address
  //
  // Description : function for validating email address that conforms to RFC 822 specs
  //
  //			   This function is converted from a Javascript written by
  //			   Sandeep V. Tamhankar (stamhankar@hotmail.com). The original Javascript
  //			   is available at http://javascript.internet.com
  //
  // Sample Valid Addresses:
  //
  //	first.last@host.com
  //	firstlast@host.to
  //	"first last"@host.com
  //	"first@last"@host.com
  //	first-last@host.com
  //	first.last@[123.123.123.123]
  //
  // Invalid Addresses:
  //
  //	first last@host.com
  //
  //
  ////////////////////////////////////////////////////////////////////////////////////////////////
  function tep_validate_email($email) {
	$valid_address = true;

	$mail_pat = '/^(.+)@(.+)$/i';
	$valid_chars = "[^] \(\)<>@,;:\.\\\"\[]";
	$atom = "$valid_chars+";
	$quoted_user='(\"[^\"]*\")';
	$word = "($atom|$quoted_user)";
	$user_pat = "/^$word(\.$word)*$/i";
	$ip_domain_pat='/^\[([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\]$/i';
	$domain_pat = "/^$atom(\.$atom)*$/i";

	if (preg_match($mail_pat, $email, $components)) {
	  $user = $components[1];
	  $domain = $components[2];
	  // validate user
	  if (preg_match($user_pat, $user)) {
		// validate domain
		if (preg_match($ip_domain_pat, $domain, $ip_components)) {
		  // this is an IP address
	  	  for ($i=1;$i<=4;$i++) {
	  		if ($ip_components[$i] > 255) {
	  		  $valid_address = false;
	  		  break;
	  		}
		  }
		}
		else {
		  // Domain is a name, not an IP
		  if (preg_match($domain_pat, $domain)) {
			/* domain name seems valid, but now make sure that it ends in a valid TLD or ccTLD
			   and that there's a hostname preceding the domain or country. */
			$domain_components = explode(".", $domain);
			// Make sure there's a host name preceding the domain.
			if (sizeof($domain_components) < 2) {
			  $valid_address = false;
			} else {
			  $top_level_domain = strtolower($domain_components[sizeof($domain_components)-1]);
			  // Allow all 2-letter TLDs (ccTLDs)
			  if (preg_match('/^[a-z][a-z]$/i', $top_level_domain) != 1) {
				$tld_pattern = '';
				// Get authorized TLDs from text file
				$tlds = file(DIR_WS_INCLUDES . 'tld.txt');
				while (list(,$line) = each($tlds)) {
				  // Get rid of comments
				  $words = explode('#', $line);
				  $tld = trim($words[0]);
				  // TLDs should be 3 letters or more
				  if (preg_match('/^[a-z]{3,}$/i', $tld) == 1) {
				   $tld_pattern .= '^' . $tld . '$|';
				  }
				}
				// Remove last '|'
				$tld_pattern = substr($tld_pattern, 0, -1);
				if (preg_match("/$tld_pattern/i", $top_level_domain) == 0) {
					$valid_address = false;
				}
			  }
			}
		  }
		  else {
	  		$valid_address = false;
	  	  }
	  	}
	  }
	  else {
		$valid_address = false;
	  }
	}
	else {
	  $valid_address = false;
	}
	if ($valid_address && ENTRY_EMAIL_ADDRESS_CHECK == 'true') {
	  if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
		$valid_address = false;
	  }
	}
	return $valid_address;
  }
?>

Steve

Same errors Steve.  I compared the files and it is the same one from github I was using.

Other ideas?

#82   Kennith

Kennith
  • Members
  • 48 posts
  • Real Name:Kennith Nielsen
  • Location:Denmark

Posted 08 January 2010 - 03:04 AM

My host havent updated to 5.3 yet but eventually they will I would like to bee one steep ahead and start fixing these errors but are the fixes backward compatibly in other words can my shop run on PHP 5.2.xx if I make the changes now?

#83   Melinda Odom

Melinda Odom
  • Members
  • 1,212 posts
  • Real Name:Melinda Odom
  • Gender:Female
  • Location:United States

Posted 08 January 2010 - 04:06 AM

It seems a shop will run on at least 5.2.12 which is what I'm using now.  The only problem is the one I just posted.

I checked the order process and checks and paypal will work.  I don't know about the other ones.

#84   steve_s

steve_s
  • Members
  • 1,580 posts
  • Real Name:steve
  • Gender:Male
  • Location:London

Posted 08 January 2010 - 07:09 PM

View PostMelinda Odom, on 08 January 2010 - 12:11 AM, said:

Same errors Steve.  I compared the files and it is the same one from github I was using.

Other ideas?
I would suggest follow through all of his posts and make all amendements, this might be down to includes/functions/general.php

I also used simple search and replace to find any other files that had ereg or eregi and split and amended them to the relevant preg ones

Steve

#85   EvilDragon

EvilDragon
  • Members
  • 7 posts
  • Real Name:Michael Mrozek

Posted 14 January 2010 - 08:10 PM

View PostProdigyMotorsport, on 05 January 2010 - 05:02 PM, said:

Yeah i have problems with the clean install from github, let me know what i can do to help.

Scott

Same problem here. Updated to PHP 5.3.1 today and it doesn't keep any osCsid. It's changing with every click, so nobody can actually buy something... :/
Any idea yet how to fix that?

#86   EvilDragon

EvilDragon
  • Members
  • 7 posts
  • Real Name:Michael Mrozek

Posted 14 January 2010 - 10:48 PM

I fixed it :)
To anybody else having problems with the oscid:
Check this thread and make sure you fix the cookie path!

I just found out that phpbb 3 had problems with php 5.3 and sessions as well and it turns out cookie handling is a bit different.
While wrong paths did work with older php Versions, they don't work anymore with the latest one.

#87   dlyxzen

dlyxzen
  • Members
  • 58 posts
  • Real Name:barry

Posted 20 January 2010 - 09:44 AM

hey guys,

i have gone through these pages and fixed many pages of mine but one still remains with problems and i cant work it out !

Deprecated: Function eregi() is deprecated in /data/http/squashcity.com.au/includes/functions/validations.php on line 91

I am getting this error among others with different lines on validations.php

How the  hell do i fix it ?!?!!

thanks

dlyxzen

#88   MrPhil

MrPhil
  • Members
  • 4,190 posts
  • Real Name:Phil
  • Gender:Male

Posted 20 January 2010 - 04:53 PM

You fix it the same way you fix all the other "eregi" problems. Is this the offending line?
 if (eregi('^[a-z]{3,}$', $tld) == 1) {
Replace it with
 if (preg_match('/^[a-z]{3,}$/i', $tld) == 1) {

If this is the line with the problem:
			 if (eregi("$tld_pattern", $top_level_domain) == 0) {
it's fixed with
			 if (preg_match("/$tld_pattern/i", $top_level_domain) == 0) {
Note that if $tld_pattern may contain slashes / , you can pick some other character such as # or : to use. Or, you add a line to modify $tld_pattern to escape slashes: / turns into \/ (that's a backslash \ followed by a slash /).

Obviously you never looked in the referenced github pages, as you would have found both fixes there.

#89   brickie

brickie
  • Members
  • 14 posts
  • Real Name:Gavin
  • Gender:Male
  • Location:Scotland

Posted 10 February 2010 - 09:23 AM

View Postspooks, on 30 August 2009 - 11:44 AM, said:

As Matt pointed out, you would replace ereg with preg_match, preg does not exist!!

so
if (ereg('^[0-9]$', $char)) $rand_value .= $char;
becomes
if (preg_match('^[0-9]$', $char)) $rand_value .= $char;

Also as has been pointed out elsewhere, a work around (till v6 at least) is:

In includes/application_top.php and admin/includes/application_top.php

find:

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

replace with:

//set the level of error reporting
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
thanks. works a treat with latest xampp and osc 2.2r2a
thanks also to germ who pointed me to this link :thumbsup:

#90   mosp

mosp
  • Members
  • 4 posts
  • Real Name:Guy Heylens

Posted 17 February 2010 - 09:02 AM

Try to replace whos_online.php eregi with this one:

<?php if (preg_match('/^(.*)' . tep_session_name() . '=[a-f,0-9]+[&]*(.*)/', $whos_online['last_page_url'], $array)) {
                 echo $array[1] . $array[2];
                 } else {
                 echo $whos_online['last_page_url'];
                 } ?>


It works for me.

Regards

#91   MrPhil

MrPhil
  • Members
  • 4,190 posts
  • Real Name:Phil
  • Gender:Male

Posted 29 March 2010 - 01:36 AM

I see that there's a lot of changes on the github version; let's hope RC3 or (better yet) Gold appears Real Soon Now. I know I've said this before, but it bears repeating: Release Candidates should freeze all development and only fix bugs. At some point you've got to get 2.2 reasonably stable and Gold out the door. Then you put in all the PHP 5.3/6.0 changes, security patches, MySQL 5 changes, and various bug and stability fixes into 2.3 alpha 1. If you don't want to add new features, that's fine, but 2.x needs to stay actively maintained until 3.0 has been Gold for a while. I can't understand why the developers keep cramming more stuff into 2.2 RC3.

Anyway, I was looking through the PHP list of deprecated functions (and other stuff), and was wondering if all of it is to be addressed soon. ereg(), etc. is taken care of. The compatibility layer takes care of register globals going away, and the long array names going away (except $HTTP_POST_FILES, which are handled elsewhere). $HTTP_USER_AGENT, $HTTP_ACCEPT_ENCODING, $DOCUMENT_ROOT, and $REMOTE_ADDR need to be changed to $_SERVER[name]. I think $PHP_SELF is handled OK. Will get_cfg_var('safe_mode') cause an error in either 5.3 or 6.0? I think the magic_quotes_gpc stuff will be OK, but I can't swear to it. call_user_method(name, object, parms...) I think is going to blow up at some point -- replace by call_user_func(array(object, name), parms...)? I see that session_register(), session_unregister(), and session_is_registered() all conflict with built-in PHP functions that are deprecated anyway as of 5.3. Does anyone know of any problems with continuing to use these names? Finally, it looks like mysql_escape_string() is adequately handled.

Does anyone know if these items are on the list to be handled soon (preferably 2.3 alpha 1)?

#92   azvareth

azvareth
  • Members
  • 2 posts
  • Real Name:Hasse Andersson
  • Gender:Male

Posted 22 April 2010 - 07:04 PM

Hi!

I recently downloaded the latest Apache, php-5.3.2-Win32-VC9-x86.msi, and latest mySQL...

I followed every applications install instructions / wizards - and get slowly everything to work well together. Finally I downloaded oscommerce-3.0a5.zip (I assume this is the latest package). The reason I setup the server that way and can't degrade is that my webhost/hotel is running the same config and they are not likely to change their configuration.

I installed it but during setup I got lots of ereg/i <something>, but I guess it did install anyway, but the warning still continued to show ecspecially in database.php...

I was wondering... (as I read all fixes here and there, I came to the conclusion that I am not skilled enough to fix it), is it possible to "redefine" this ereg whatever so that the oscommerceApp for a moment at least can behave in a functional manner.
like:

IFDEF <name>
  UNDEF <name>
  DEF <name = "call this function()/class()/object() whatever instead">
ENDIF

and then make an include from every file that use this ereg/i stuff.

If not possible, does anyone have made an automated patch script or something that match the errors and then fix them? if so, would you be kind souls and share this with n00b Lamers like myself?

by the way: the latest error that was shown to me looked like this: (I was trying to copy and paste but I could not so I link to an partial image)
[img]http://novallie.se/aros/ereg_i.gif[/img]

the error is one page long...

ohhh! and last, I am new to Apache, I am new to PHP, I am new to mySQL, I am new to oscommerce - the only reason to install it was to see if I could sell something (secondhand...), and if oscommerce was good to use for that.

#93   MrPhil

MrPhil
  • Members
  • 4,190 posts
  • Real Name:Phil
  • Gender:Male

Posted 22 April 2010 - 07:48 PM

DO NOT, I repeat, DO NOT use osC version 3 unless you are an EXPERT programmer. It is only "alpha" level -- very early test version subject to much revision. Besides, this is the 2.2 section of the discussions (you're in the wrong place). 2.2 RC2a is the current (and probably final) version 2 release.

No, there are no automated fixes or redefines you can do. If you had read the discussions on "ereg" and PHP 5.3, you would know that the arguments to the function also have to be changed.

#94   azvareth

azvareth
  • Members
  • 2 posts
  • Real Name:Hasse Andersson
  • Gender:Male

Posted 22 April 2010 - 07:53 PM

and finally I see that I am in the wrong forum part... this (above) should be moved to version 3 part I guess...


//Sorry!

[late edit]

Quote

No, there are no automated fixes or redefines you can do. If you had read the discussions on "ereg" and PHP 5.3, you would know that the arguments to the function also have to be changed.
I did understood it loosely (I am not an expert programmer so...), and what I meant was to use the older version, by copy the code from old PHP releases and include/merge them in to oscommerce and bypass the newer version (but I guess you thought of that already). - no more comments from me here, i go to the right place if I can find it...

thanks for your reply!

Edited by azvareth, 22 April 2010 - 08:03 PM.


#95   Dennisra

Dennisra
  • Members
  • 515 posts
  • Real Name:Joseph D. Jefferson
  • Gender:Male

Posted 06 May 2010 - 05:48 PM

This is in admin/modules.php for USPS shipping:

//USPS 4.0
if (tep_not_null($action)) {
switch ($action) {
case 'save':
while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
if( is_array( $value ) ){
$value = implode( ", ", $value);
$value = ereg_replace (", --none--", "", $value);
}
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
}
tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
break;
case 'install':
//USPS 4.0

I have replaced:
$value = ereg_replace (", --none--", "", $value);
with this:
$value = preg_replace ("/, --none--/", "", $value);
and although it gets rid of the errors the USPS shipping module still does not work.

Have I placed the deliminators correctly? What is the correct placement?

#96   ivanibam

ivanibam
  • Members
  • 5 posts
  • Real Name:cupi cabola

Posted 09 June 2010 - 04:02 PM

hi i'm new here..and i would like to ask regarding the function of my "add to cart" and "create new account"

the account was created but there is a deprecated warning said
"Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\oscommerce-2.2rc2a\VoodooPC\includes\functions\general.php on line 61"

the following line is written "    $string = ereg_replace(' +', ' ', trim($string));"

also there is more problem such as
    if (eregi($mail_pat, $email, $components)) {
      if (eregi($user_pat, $user)) {
        if (eregi($ip_domain_pat, $domain, $ip_components)) {
          if (eregi($domain_pat, $domain)) {
              if (eregi('^[a-z][a-z]$', $top_level_domain) != 1) {
                  if (eregi('^[a-z]{3,}$', $tld) == 1) {
                if (eregi("$tld_pattern", $top_level_domain) == 0) {


        if (ereg('^[0-9]$', $char)) $rand_value .= $char;


I really need it to work, cos it's for my school project and i'm testing it in the localhost..

thanks alot..

#97   DunWeb

DunWeb

    The Censored One

  • Members
  • 12,814 posts
  • Real Name:Chris
  • Gender:Male
  • Location:Ontario, Canada

Posted 09 June 2010 - 04:23 PM

Cupi,

Try this:


http://addons.oscommerce.com/info/7394



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)

#98   ivanibam

ivanibam
  • Members
  • 5 posts
  • Real Name:cupi cabola

Posted 09 June 2010 - 06:06 PM

View PostDunWeb, on 09 June 2010 - 04:23 PM, said:


its very helpful Chris..thanks a lot. I manage to decrease the problem of having deprecated things again..but still got problem about warning signs
such as:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\oscommerce-2.2rc2a\VoodooPC\includes\classes\email.php on line 522

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\oscommerce-2.2rc2a\VoodooPC\includes\classes\email.php:522) in C:\xampp\htdocs\oscommerce-2.2rc2a\VoodooPC\includes\functions\general.php on line 33


and

comes up new problem appear in my product listing..

Warning: substr() expects parameter 3 to be long, string given in C:\xampp\htdocs\oscommerce-2.2rc2a\VoodooPC\includes\modules\new_products.php on line 36

but the checkout works amazingly perfect to give me the confirmation of the transaction for the customer..thanks alot btw..i just need a little help about those two problem i mention above...

#99   Nestorin

Nestorin
  • Members
  • 1 posts
  • Real Name:Nestor Fernandez

Posted 22 July 2010 - 08:47 PM

First, thanks to all you. Great notes!!!!
On the comment...
"As Matt pointed out, you would replace ereg with preg_match, preg does not exist!!

so
if (ereg('^[0-9]$', $char)) $rand_value .= $char;
becomes
if (preg_match('^[0-9]$', $char)) $rand_value .= $char;

------------------------------------ Take care --------
On
if (preg_match('^[0-9]$', $char)) $rand_value .= $char
Must be
if (preg_match('^[0-9]$^', $char)) $rand_value .= $char

Agregate de delimiter "^" after "$"

Edited by Nestorin, 22 July 2010 - 08:52 PM.


#100   DunWeb

DunWeb

    The Censored One

  • Members
  • 12,814 posts
  • Real Name:Chris
  • Gender:Male
  • Location:Ontario, Canada

Posted 22 July 2010 - 09:41 PM

While this thread stumbles along somewhat aimlessly trying to figure out of to make your current RC2a websites PHP 5.3 compliant, everyone COULD just download the patch notes and the drop on top files for RC2a and spend the time you use posting here to do other things.  :-"


http://addons.oscommerce.com/info/7394



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)