Deprecated: Function eregi() [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Function eregi() is deprecated
Hello I am getting this error
Deprecated: Function eregi() is deprecated in /home/u578804202/public_html/includes/functions.php on line 4
Here is my code:
if(eregi($file,$_SERVER['REQUEST_URI'])) {
die("Sorry but you cannot access this file directly for security reasons.");
}

As you should, it's an old function that is deprecated, user stristr() instead
if(stristr($_SERVER['REQUEST_URI'],$file)) {
die("Sorry but you cannot access this file directly for security reasons.");
}

You should use preg_match instead:
if (!preg_match("~{$file}~i,", $_SERVER['REQUEST_URI'])) {
die("Sorry but you cannot access this file directly for security reasons.");
}

Related

PHP 5.1 to PHP 7.1 broke contact form [duplicate]

This question already has answers here:
ereg/eregi replacement for PHP 5.3 [duplicate]
(4 answers)
How to replace eregi()
(2 answers)
How can I convert ereg expressions to preg in PHP?
(4 answers)
Alternative to eregi() in php [duplicate]
(1 answer)
How to change PHP's eregi to preg_match [duplicate]
(2 answers)
Closed 4 years ago.
The web hosting service provider upgraded to PHP 7.1 and it broke the contact form of the page. I've narrowed it down to this piece of code:
function check_email($mail)
{
$email_host = explode("#", $mail);
$email_host = $email_host['1'];
$email_resolved = gethostbyname($email_host);
if ($email_resolved != $email_host && #eregi("^[0-9a-z]([-_.~]?[0-9a-z])*#[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$mail))
$valid = 1; return $valid;
}
I've found that the eregi function is no longer supported in PHP 7.1 but I dont know how and with what i should replace it.
Have a look at the documentation of eregi function in php.net:
Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
preg_match() (with the i (PCRE_CASELESS) modifier)
You should always have a look there when it comes do deprecated functions.
For validating email addresses you could also use filter_var now:
if (filter_var('test#example.com', FILTER_VALIDATE_EMAIL)) {
echo "Email valid.";
}

Deprecated: Function eregi() is deprecated in [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 9 years ago.
I'm trying to submit values to the database but i get an error message
Deprecated: Function eregi() is deprecated in
C:\wamp\www\OB\admin_add_acc.php on line 20 and 27
Here is the code:
<?php
include 'db_connect.php';
if(isset($_POST['Submit']))
{
$acc_type=ucwords($_POST['acc_type']);
$minbalance=ucwords($_POST['minbalance']);
if (!eregi ("^[a-zA-Z ]+$", stripslashes(trim($acc_type))))//line 20
{
echo "Enter Valid Data for Account Type!";
exit(0);
}
else
{
if (!eregi ("^[0-9 ]+$", stripslashes(trim($minbalance))))//line 27
{
eregi() is deprecated as of PHP 5.3, use preg_match() instead.
Note that preg_match() is only case insensitive when you pass the i modifier in your regular expression.
include 'db_connect.php';
if(isset($_POST['Submit']))
{
$acc_type=ucwords($_POST['acc_type']);
$minbalance=ucwords($_POST['minbalance']);
// Removed A-Z here, since the regular expression is case-insensitive
if (!preg_match("/^[a-z ]+$/i", stripslashes(trim($acc_type))))//line 20
{
echo "Enter Valid Data for Account Type!";
exit(0);
}
else
{
// \d and 0-9 do the same thing
if (!preg_match("/^[\d ]+$/", stripslashes(trim($minbalance))))//line 27
{
}
}
}
From Wikipedia:
Deprecation is a status applied to a computer software feature, characteristic, or practice indicating it should be avoided, typically because of it being superseded.
Take a look at the PHP manual for eregi. As you can see, it has the following warning:
This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
Further down the page there is some advice on what to use instead:
eregi() is deprecated as of PHP 5.3.0. preg_match() with the i (PCRE_CASELESS) modifier is the suggested alternative.
So you can use the preg_match function instead.
You can find the answer here in the manual.Since its a Deprecated function in the php version you are using you will get that warning.Instead of ergi you can use preg_match.See the manual for preg match

split() deprecated. How to convert? [duplicate]

This question already has answers here:
Deprecated: Function split() is deprecated. How to rewrite this statement?
(4 answers)
Closed 9 years ago.
I have a piece of code that's using the split() function. PHP is complaining that the function is deprecated. How can this be converted to a non deprecated split?
if(!empty($vis_settings['url']['urls'])){
$split_urls=split("[\n ]+",(string)$vis_settings['url']['urls']);
You can use preg_split.
$split_urls = preg_split("/[\n ]+/",(string) $vis_settings['url']['urls']);

Call-time pass-by-reference issue in php [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Call-time pass-by-reference has been deprecated;
function getLib($pfComponentType,$pfComponentCode,$componentCode)
{
if($temp=require_once($this->getConfig($pfComponentType,$pfComponentCode,'librariesPath').$componentCode.'.php'))
{
$obj_lib = __NAMESPACE__.'\\'.$componentCode;
return new $obj_lib(&$this);
}
else return NULL;
}
I am getting a error saying that Call-time pass-by-reference has been removed in the line 6 of above function i.e., return new $obj_lib(&$this);
$obj_lib does not have a pass by reference parameter, so you cannot pass it a reference. Remove the & from &$this, or add & to the parameter wherever $obj_lib is defined

Warning: function eregi() is deprecated [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Function eregi() is deprecated
I have created a contact form with PHP, but am getting a warning:
Deprecated: Function eregi() is deprecated in D:\hosting\9606426\html\Websites\LuxeBeauty\1\contact.php on line 9
This is line 9:
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."#"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-
z]{2,}"."$",$email )){
...
}
What should I do to fix this?
eregi has been depreciated, which means that you'll need to switch to:
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error.="Invalid email address entered";
$errors=1;
}

Categories