CodeIgniter Forums
Running stripslashes on all $_POST in all controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Running stripslashes on all $_POST in all controllers (/showthread.php?tid=31485)



Running stripslashes on all $_POST in all controllers - El Forum - 06-21-2010

[eluser]stef25[/eluser]
The server I'm currently using is running PHP 5.3 with magic quotes on. I have a function that will run stripslashes() on all $_POST data to fix quotes being added on DB output - where is the best place to put and run this function, short of having to manually add it to all functions in all controllers? This is what I've been doing so far but occasionally I come across a page where some quotes slipped through.


Running stripslashes on all $_POST in all controllers - El Forum - 06-21-2010

[eluser]n0xie[/eluser]
Either use a hook or just dump it into the index.php
Code:
if (get_magic_quotes_gpc()) {
    function magicQuotes_awStripslashes(&$value, $key) {$value = stripslashes($value);}
    $gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    array_walk_recursive($gpc, 'magicQuotes_awStripslashes');
}



Running stripslashes on all $_POST in all controllers - El Forum - 06-21-2010

[eluser]stef25[/eluser]
Thanks for that.

Actually it just occurred to me that I don't need to run this on the $_POST but on the data that's coming out of the DB. What would be the best way to do this in CI?


Running stripslashes on all $_POST in all controllers - El Forum - 06-21-2010

[eluser]n0xie[/eluser]
The data in the database shouldn't contain slashes. If it does you can just escape the output when 'printing'...