Information and support for products of WithinWeb.com

 header image 2

get_magic_quotes_gpc in PHP6

July 3rd, 2012 · No Comments

In PHP6, get_magic_qu0tes_gpc will be depreciated, but you may still want to be able to test for it if you do not know which version of PHP it will be running on.

Here are two possible ways of how this might be done.  Both of these create a new function called is_get_magic_quotes_gpc to make it easier to search and replace in a number of files.

First method :

<?php

/**
Returns true if have to make allowances for magic quotes or not
Returns true if magic quotes are on false otherwise
Test which version of PHP you have and make allowences as appropriate
**/
function is_get_magic_quotes_gpc() {

if ( version_compare(phpversion(), ‘6’, ‘<‘) ) {

if ( get_magic_quotes_gpc() ) {
return true;
}
else
{
return false;
}

}
else
{
return false;
}

}
?>

Second method :

<?php

/**
Returns true if have to make allowances for magic quotes or not
Returns true if magic quotes are on false otherwise
Test if the function exists or not and then make allowances as appropriate
**/
function is_get_magic_quotes_gpc() {

if ( function_exists(“get_magic_quotes_gpc”) )
{
if ( get_magic_quotes_gpc() ) {
return true;
}
else
{
return false;
}
}
else
{
return false;
}

}

?>

Both of these can be tested using :

<?php

if ( is_get_magic_quotes_gpc() ) {
echo(“yes”);
}
else
{
echo(“no”);
}

echo(“<p>php version : ” . phpversion() . “</p>”);

?>

Tags: General PHP

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.