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

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.

Either use a hook or just dump it into the index.php
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');

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?

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