Welcome Guest, Not a member yet? Register   Sign In
Running stripslashes on all $_POST in all controllers
#1

[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.
#2

[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');
}
#3

[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?
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB