Zet dit stukje code in elk script dat je gebruikt. Zorg wel dat het maximaal en minimaal 1 keer word uitgevoerd.
17-12-2005 11:01
Opzich natuurlijk handig, al staat in dat andere script -als je de comments bij elkaar raapt- hetzelfde.
Wat ik wel zou doen is je logica iets omdraaien, zodat de functie alleen uitgevoerd wordt als gpc = on.
Nu gooi je bij elke request opnieuw die functie er overheen, terwijl dat helemaal niet nodig is als gpc = off
1 2 3 | Post hier de source-code van je script. Alle informatie tussen <? ... ?> en <?php ... ?> zal automatisch worden getoond in color-coding.
Let op! Het is niet de bedoeling om hier een link naar je website te plaatsen. Post hier gewoon de code, veel simpeler, sneller en meer kans dat het blijft staan. |
17-12-2005 12:54
Zo wou ik het eerst doen... Ik kreeg op mijn eigen server geen error, maar op lycos.nl wel, dus ik nam aan dat het niet helemaal geldig PHP was...
Dat zou nl. beter zijn geweest, denk ik, bovenstaande.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php
function undo_magic_quotes_gpc($mGetPostCookieRequestVariable = null)
{
if (get_magic_quotes_gpc() == 1)
{
if (is_null($mGetPostCookieRequestVariable))
{
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
undo_magic_quotes_gpc($_REQUEST);
}
else
{
if (is_array($mGetPostCookieRequestVariable))
{
return array_map('undo_magic_quotes_gpc', $mGetPostCookieRequestVariable);
}
else
{
return stripslashes($mGetPostCookieRequestVariable);
}
}
}
else
{
return $mGetPostCookieRequestVariable
}
}
undo_magic_quotes_gpc();
?> |
06-09-2006 08:22
Vermeld hier alle zaken betreffende valkuilen, handige informatie, (installatie-)instructies e.d.
06-09-2006 09:18
$_COOKIE kan wel degelijk arrays bevatten.
15-04-2008 11:24
"$_COOKIE kan wel degelijk arrays bevatten.
Re: undo_magic_quotes_gpc()
<?php
setcookie('hoi[test]', 'blaat', time() + 3600);
?> "
strings alleen .
verder niet echt interessant om in de lib te zetten denk ik
15-04-2008 13:37
Het nut hiervan snap ik absoluut niet!
Je kan ze veel makkelijker in htaccess uitzetten!
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
</IfModule>
Daarnaast vind ik het een matig voorbeeld van recursie binnen php.
- Waarom zo'n lange $vanNaamBinnenEenFunctie. Nergens voor nodig IMO.
- d.m.v. een static kan je de magic quotes check gemakkelijk intern in de functie verwerken.
- __FUNCTION__ is hier flexibeler.
En dan nog heb je ook nog zoiets als:
http://www.php.net/manual/en/function.filter-input-array.php in combinatie met FILTER_SANITIZE_MAGIC_QUOTES...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php
function unquote($data){
static $on = NULL;
if(!isset($on)){
$on = ini_get('magic_quotes_gpc');
}
return ((is_array($data)) ? array_map(__FUNCTION__, $data) : (($on) ? stripslashes($data) : $data));
}
function unquote($data){
static $on = NULL;
if(!isset($on)) $on = ini_get('magic_quotes_gpc');
return ((is_array($data)) ? array_map(__FUNCTION__, $data) : ((!!!$on) ? stripslashes($data) : $data));
}
?> |
16-04-2008 19:28
In PHP.ini uitzetten is inderdaad de beste oplossing.
Als dat niet kan inderdaad in .htaccess.
Maar als ook dat niet gaat biedt dit script een oplossing.
Daarnaast is het gewoon vereist dat je dit aanroept, want er zijn genoeg kneusjes die een script downloaden en hier niets vanaf weten.
De filter-extensie is misschien wel leuk, maar magic-quotes gaan er gelukkig uit in PHP 6. Dat houdt wel in dat je bij een PHP upgrade je je scripts weer mag gaan updaten... Hier niet: Je zet er if (function_exists('get_magic_quotes_gpc')) omheen en klaar ben je.
1 2 3 | Post hier de source-code van je script. Alle informatie tussen <? ... ?> en <?php ... ?> zal automatisch worden getoond in color-coding.
Let op! Het is niet de bedoeling om hier een link naar je website te plaatsen. Post hier gewoon de code, veel simpeler, sneller en meer kans dat het blijft staan. |
01-04-2009 11:13
Bij een test (een tijd geleden) met php6 kwam ik erachter dat de functie get_magic_quotes_gpc() er ook uit gaat.
Misschien dus eerst een function_exist of een ini check?
1 2 3 | Post hier de source-code van je script. Alle informatie tussen <? ... ?> en <?php ... ?> zal automatisch worden getoond in color-coding.
Let op! Het is niet de bedoeling om hier een link naar je website te plaatsen. Post hier gewoon de code, veel simpeler, sneller en meer kans dat het blijft staan. |
01-04-2009 14:19
Volgens mij gaan de hele magic quotes eruit, dus heb je dit niet eens nodig in php 6...
1 2 3 | Post hier de source-code van je script. Alle informatie tussen <? ... ?> en <?php ... ?> zal automatisch worden getoond in color-coding.
Let op! Het is niet de bedoeling om hier een link naar je website te plaatsen. Post hier gewoon de code, veel simpeler, sneller en meer kans dat het blijft staan. |
01-04-2009 15:32
Misschien is het handig om fouten te voorkomen dat je een variabel/constante laat zetten als je de slashes verwijdert hebt. En dan ook nog aan het begin controleren of dat is gezet (oid)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php
if (get_magic_quotes_gpc() == 1) {
if(!defined('UNDO_GPC')) {
function undo_magic_quotes_gpc($pmVariable) {
return ((is_array($pmVariable)) ? array_map('undo_magic_quotes_gpc', $pmVariable) : stripslashes($pmVariable));
}
$_GET = !empty($_GET) ? undo_magic_quotes_gpc($_GET) : '';
$_POST = !empty($_POST) ? undo_magic_quotes_gpc($_POST) : '';
$_COOKIE = !empty($_COOKIE) ? undo_magic_quotes_gpc($_COOKIE) : '';
$_REQUEST = !empty($_REQUEST) ? undo_magic_quotes_gpc($_REQUEST) : '';
define('UNDO_GPC', true);
}
}
?> |
01-04-2009 22:55
Deze voorkomt ook dat het uitgevoerd wordt op PHP 6 of hoger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php
if(version_compare(PHP_VERSION, '6.0.0') === -1 && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === '1' && defined('UNDO_GPC') === false)
{
function undo_magic_quotes_gpc($aArray)
{
return is_array($aArray) ? array_map('undo_magic_quotes_gpc', $aArray) : stripslashes($aArray);
}
$_GET = undo_magic_quotes_gpc($_GET);
$_POST = undo_magic_quotes_gpc($_POST);
$_COOKIE = undo_magic_quotes_gpc($_COOKIE);
$_FILES = undo_magic_quotes_gpc($_FILES);
$_REQUEST = undo_magic_quotes_gpc($_REQUEST);
define('UNDO_GPC', true);
}
?> |
14-05-2009 22:10
" get_magic_quotes_gpc() === '1' "
get_magic_quotes_gpc() geeft altijd een integer terug en geen string. Hierdoor voldoe je nooit aan de voorwaarde en ga je nooit de if in.
Even de quotjes om de 1 weghalen, zodat er vergeleken wordt met een integer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php
if(version_compare(PHP_VERSION, '6.0.0') === -1 && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 && defined('UNDO_GPC') === false)
{
function undo_magic_quotes_gpc($aArray)
{
return is_array($aArray) ? array_map('undo_magic_quotes_gpc', $aArray) : stripslashes($aArray);
}
$_GET = undo_magic_quotes_gpc($_GET);
$_POST = undo_magic_quotes_gpc($_POST);
$_COOKIE = undo_magic_quotes_gpc($_COOKIE);
$_FILES = undo_magic_quotes_gpc($_FILES);
$_REQUEST = undo_magic_quotes_gpc($_REQUEST);
define('UNDO_GPC', true);
}
?> |