Jump to content

Recommended Posts

Well hello everyone,

 

I've installed a fresh copy of Vanilla which is a lightweight forum.

But, I got a "Deprecated: Function eregi() is deprecated in C:\wamp\www\xfm\library\Framework\Framework.Class.Validator.php on line 93" when a user attempted to sign up.

 

So I went to find that function and found:

// Validate all defined variables
// Returns boolean value indicating un/successful validation
function Validate() {
	// If a regexp was supplied, attempt to validate on it (empty strings allowed)
	if($this->ValidationExpression != '' && $this->Value != '') {
		if(!eregi($this->ValidationExpression, $this->Value)) {
			$this->isValid = 0;
			$this->Context->WarningCollector->Add($this->ValidationExpressionErrorMessage);
		}
	}

 

So what I did was change it to:

 

	// Validate all defined variables
// Returns boolean value indicating un/successful validation
function Validate() {
	// If a regexp was supplied, attempt to validate on it (empty strings allowed)
	if($this->ValidationExpression != '' && $this->Value != '') {
		if(!preg_match(/'$this->ValidationExpression/', $this->Value)) {
			$this->isValid = 0;
			$this->Context->WarningCollector->Add($this->ValidationExpressionErrorMessage);
		}
	}

 

I no longer get the error but, now the board gives a:

 

You did not supply a properly formatted value for email.

 

But the thing is the e-mail is valid, anyone know of a solution?

Link to comment
https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/
Share on other sites

  • 1 year later...

Hello,

 

I have the same problem, here is my code:

// DEFINE FUNCTIONS
function spamcheck($field)
{
    //eregi() performs a case insensitive regular expression match
    if (eregi("to:", $field) || eregi("cc:", $field) || eregi("bcc:", $field)) {
        return true;
    } else {
        return false;
    }
}
function check_email($mail_address)
{
    $pattern = "/^[\w-]+(\.[\w-]+)*@";
    $pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
    if (!preg_match($pattern, $mail_address)) {
        return true;
    } else {
        return false;
    }
}

//END FUNCTIONS

Every time I run this code (contact form) I get the error "Deprecated: Function eregi() is deprecated ..."

 

However the email is sent.

 

Any solution?? Thanks in advance!

Any solution?? Thanks in advance!

 

The proper solution is to migrate your code to using one or more functions which are not considered deprecated. For regular expressions, that would be the PCRE functions (preg_match(), preg_replace(), etc.). An introduction to the differences between POSIX (ereg(), ereg_replace(), etc.) and PCRE functions can be found in the manual.

 

Many times, simple string functions can also be used. In your case, the eregi() function calls could be changed to use stripos().

Salathe,

 

thanks but if I use stripos() i get an error as if the email field was wrong or not filled in.

 

I've seen some answers that recomend to use preg_match() however when I use this one I ge : Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash 

 

Any other possible solutions?

 

Thx in advance

Canguingo, please take the time to read the documentation (it takes a lot of effort to write it!) and understand how to use the functions that are suggested. It looks like you're just using them incorrectly. I gave you plenty of links through to the manual showing everything that you need to know.

 

stripos

 

Your code was:  if (eregi("to:", $field) || eregi("cc:", $field) || eregi("bcc:", $field)) {

 

Each of the eregi("...", $field) should become (stripos($field, "...") !== FALSE).  That will behave in the same way as your old code.

 

Another option is to use an equivalent PCRE regex:  if (preg_match('/to:|cc:|bcc:/', $field)) {

 

delimiters

 

As mentioned in the manual (I gave you this link earlier), PCRE patterns need delimiters whereas POSIX ones do not.  Your check_email() function already uses PCRE and has delimiters.

Thanx, I know you gave me that link already and I tryed to read it and understand it but for me is in chiness... I'm a bit new here. sorry about that.

 

I've try to use both examples you gave me. and with both i get the error that the email is invalid. See my code:

// DEFINE FUNCTIONS
function spamcheck($field)
{
    //eregi() performs a case insensitive regular expression match. old comment..

    if (preg_match("/to:|cc:|bcc:/", $field)) {
        return true;
    }
    else {
        return false;
    }
}
function check_email($mail_address)
{
    $pattern = "/^[\w-]+(\.[\w-]+)*@";
    $pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
    if (!preg_match($pattern, $mail_address)) {
        return true;
    } else {
        return false;
    }
}


//END FUNCTIONS

if (isset($_REQUEST['send'])){
      if (($_REQUEST['naam']=="") OR ($_REQUEST['naam']=="")) {
                     echo "<p><b><br><FONT face=Verdana color=#ff7500 size=2>El campo 'nombre' es obligatorio.</FONT></b></b><p>";
      }
      elseif (isset($_REQUEST['email']))
        {
        //check if the email address is invalid
        $checkcode = $_REQUEST['email'].$_REQUEST['bericht'].$_REQUEST['adres'].$_REQUEST['pcplaats'].$_REQUEST['bedrijf'].$_REQUEST['naam'];
        $mailcheck = spamcheck($checkcode);
        if ($mailcheck==TRUE)
         {
         echo "Nice try.";
         $klaar =1;
         }
        else { 
       // check if address is an address 
         $email = $_REQUEST['email']; 
            if (check_email($email)) {
               //send email
               $subject = "Mensaje desde rcr66.com";
               $message = "De: ".$_REQUEST['naam']."( $email )";
               
               $message .= "\n Calle: ".$_REQUEST['adres'];
               $message .= "\n Ciudad: ".$_REQUEST['pcplaats'];
               $message .= "\n Mensaje:";
               $message .= $_REQUEST['bericht'];
               mail("$emailto", "$subject", $message, "From: $email" );
               echo "<p><br><b><FONT face=Verdana color=#ff7500 size=2>Gracias por tu mensaje, prometemos contestarte lo antes posible</FONT></b></br></p>";
               $klaar =1;
            }
            else {
               echo "<p><b><br><font face=Verdana color=#ff7500 size=2>Fout email</font></br></b></p>";
            }
                           }
      }
}

 

Any idea where else do i need to change?

Your check_email() function returns TRUE if the email address does not match the regular expression and FALSE if the address does match the regular expression.  Your script looks to see if check_email() returned TRUE, and if it did then the email is sent via mail().

 

This logic seems backward to me: the email gets sent if the address does not look like an email address.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.