Reputation: 4069
I'm using a shared host server which I can't control.
The PHP is initialized with the --enable-magic-quotes
parameter so I must use stripslashes
to retrieve unescaped $_GET
parameters.
The problem is that I cannot detect this behavior at runtime (PHP 5.4.41): all of these functions return "false":
ini_get(magic_quotes_sybase)
get_magic_quotes_gpc()
get_magic_quotes_runtime()
Is there any way I can detect on runtime, without changing server configuration, whether I need to use stripslashes
or not?
EDIT I use WordPress platform, my own PHP code is quite minor.
Upvotes: 1
Views: 1119
Reputation: 94662
Here you go
get_magic_quotes_gpc()
Returns 0 if magic_quotes_gpc is off, 1 otherwise. Or always returns FALSE as of PHP 5.4.0 because it no longer exists as of PHP5.4.0
if (get_magic_quotes_gpc()) {
$lastname = stripslashes($_GET['lastname']);
} else {
$lastname = $_GET['lastname'];
}
I have to admit thats a complete ripoff from the php manual
As magic_quotes were removed as of PHP5.4.0 you might want to do this instead :
if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
$lastname = stripslashes($_GET['lastname']);
} else {
$lastname = $_GET['lastname'];
}
Upvotes: 3
Reputation: 1222
If you can use .htaccess try
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
</IfModule>
Upvotes: 1