72

I'm getting this message when I try to run a php script I have to use but did not write.

Deprecated: Function set_magic_quotes_runtime() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/fpdf.php on line 1810

Here is line 1810:

set_magic_quotes_runtime(0);

If this is a deprecated function, what can I replace it with?

Thank you very much!

Shawn
  • 10,931
  • 18
  • 81
  • 126
  • Related [PHP 7.4 deprecated get_magic_quotes_gpc function alternative](https://stackoverflow.com/a/61260285/1839439) – Dharman May 11 '22 at 11:25

12 Answers12

72

Check if it's on first. That should get rid of the warning and it'll ensure that if your code is run on older versions of PHP that magic quotes are indeed off.

Don't just remove that line of code as suggested by others unless you can be 100% sure that the code will never be run on anything before PHP 5.3.

<?php
// Check if magic_quotes_runtime is active
if(get_magic_quotes_runtime())
{
    // Deactivate
    set_magic_quotes_runtime(false);
}
?>

get_magic_quotes_runtime is NOT deprecated in PHP 5.3.
Source: http://us2.php.net/get_magic_quotes_runtime/

philfreo
  • 41,941
  • 26
  • 128
  • 141
  • @stereofrog - are you sure? I haven't tested but the get function doesn't show that in the documentation, while the set function clearly does. – philfreo Feb 08 '10 at 04:24
  • The get function always returns false in PHP > 5.4, but it is not yet deprecated. – mbomb007 Feb 01 '19 at 20:03
  • 6
    Unfortunately ```get_magic_quotes_runtime()``` is deprecated as of PHP 7.4.0 so this approach is no longer good. – worriorbg Nov 24 '20 at 23:53
32

I used FPDF v. 1.53 and didn't want to upgrade because of possible side effects. I used the following code according to Yacoby:

Line 1164:

if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    $mqr=get_magic_quotes_runtime();
    set_magic_quotes_runtime(0);
}

Line 1203:

if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    set_magic_quotes_runtime($mqr);
}
testing
  • 19,681
  • 50
  • 236
  • 417
14

Since Magic Quotes is now off by default (and removed in PHP v8), you can just remove that function call from your code.

Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81
Doug T.
  • 64,223
  • 27
  • 138
  • 202
  • 3
    see my answer on why this may not be a good idea ( http://stackoverflow.com/questions/2217955/how-can-i-replace-the-deprecated-set-magic-quotes-runtime-in-php/2218021#2218021 ) – philfreo Feb 07 '10 at 19:45
7

You don't need to replace it with anything. The setting magic_quotes_runtime is removed in PHP6 so the function call is unneeded. If you want to maintain backwards compatibility it may be wise to wrap it in a if statement checking phpversion using version_compare

Yacoby
  • 54,544
  • 15
  • 116
  • 120
  • 1
    And to back this with code: `if(version_compare(PHP_VERSION, '5.3.0', '<')) set_magic_quotes_runtime(0);` – Dzhuneyt Oct 08 '13 at 09:39
6

Upgrade to version 1.6 of FPDF.

Martin
  • 61
  • 1
  • 1
6

In PHP 7 we can use:

ini_set('magic_quotes_runtime', 0);

instead of set_magic_quotes_runtime(0);

Josh Rumbut
  • 2,640
  • 2
  • 32
  • 43
RAMIL T.K
  • 61
  • 1
  • 3
5
ini_set('magic_quotes_runtime', 0)

I guess.

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
user187291
  • 53,363
  • 19
  • 95
  • 127
5

I fixed mine by removing that line of code by commenting them out and it worked fine.

//if(get_magic_quotes_runtime())
//  @set_magic_quotes_runtime(0);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
3

Gust add the prefix "@" before the function to be @set_magic_quotes_runtime(0); Not supported anymore in php 5.4, and don't remove or disable the function

Alaa Sadik
  • 1,029
  • 12
  • 19
2

add these code into the top of your script to solve problem

@set_magic_quotes_runtime(false);
ini_set('magic_quotes_runtime', 0);
Somwang Souksavatd
  • 4,947
  • 32
  • 30
1

Just override them like:

if (!function_exists('set_magic_quotes_runtime')) {
    function set_magic_quotes_runtime($new_setting) {
        return true;
    }
}

if (!function_exists('split')) {
    function split($pattern, $string, $limit = -1) {
        return explode($pattern, $string);
    }
}
CodeWhisperer
  • 1,143
  • 2
  • 19
  • 39
0

Update this function :

if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  set_magic_quotes_runtime(0);
}
else {
  ini_set('magic_quotes_runtime', 0);
}
$magic_quotes = get_magic_quotes_runtime();
$file_buffer = fread($fd, filesize($path));
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
if ($magic_quotes) {
  if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    set_magic_quotes_runtime($magic_quotes);
  }
  else {
    ini_set('magic_quotes_runtime', $magic_quotes);
  }
}

return $file_buffer;
Praveen Kumar
  • 864
  • 2
  • 9
  • 33