Results 1 to 2 of 2

Thread: page specific php.ini

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default page specific php.ini

    Hi,

    Is there a way to use php to turn off magic quotes for a particular file if it is on without editing the php.ini file or .htaccess?
    Last edited by james438; 05-03-2011 at 11:25 PM. Reason: changed to resolved.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Silly me. The answer is right on the php.net site here.

    Just insert the following near or at the top of your php script.
    Code:
    <?php
    if (get_magic_quotes_gpc()) {
        $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        while (list($key, $val) = each($process)) {
            foreach ($val as $k => $v) {
                unset($process[$key][$k]);
                if (is_array($v)) {
                    $process[$key][stripslashes($k)] = $v;
                    $process[] = &$process[$key][stripslashes($k)];
                } else {
                    $process[$key][stripslashes($k)] = stripslashes($v);
                }
            }
        }
        unset($process);
    }
    ?>
    It is not as efficient as changing the php.ini file, but it can make your scripts more portable.
    Last edited by james438; 05-03-2011 at 11:26 PM. Reason: added info.
    To choose the lesser of two evils is still to choose evil. My personal site

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •