Jump to content

PHP Post is returning single quote character


zander1983

Recommended Posts

Hi

I have a simple form and when the user submits, php is putting a \ before every single quote entered in the field. So for example, if a user enters O'Neill, once i do

$lastName = $_POST["lastname"];

 

$lastName comes back as: O\'Neill

 

is there some way I can turn this off?

Link to comment
Share on other sites

The magic_quotes_gpc setting is enabled on your server. If you have access to the php.ini file you can turn this off. If you are on a shared server you will not be able to do this.

 

Depending on your situation it is probably better to "cleanse" your user input in a server independent manner - i.e. using a process that will work no matter what the server setting is. there is an example process in the PHP manual for this - along with other useful information on the subject.

 

http://www.php.net/manual/en/function.get-magic-quotes-gpc.php

Link to comment
Share on other sites

Put this script in a file, and include it into all processing scripts.  It will strip the slashes automatically.

<?php
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
    function GPCStrip($arr)
    {
        if (is_array($arr))
        {
            foreach ($arr AS $arrKey => $arrVal)
            {
                $arr[$arrKey] = GPCStrip($arrVal);
            }
        }
        else if (is_string($arr))
        {
            $arr = stripslashes($arr);
        }
        return $arr;
    }
    $_GET = GPCStrip($_GET);
    $_POST = GPCStrip($_POST);
    $_COOKIE = GPCStrip($_COOKIE);
    if (is_array($_FILES))
    {
        foreach ($_FILES AS $key => $val)
        {
            $_FILES[$key]['tmp_name'] = str_replace('\\', '\\\\', $val['tmp_name']);
        }
    }
    $_FILES = GPCStrip($_FILES);
}
if (function_exists('set_magic_quotes_runtime'))
{
    set_magic_quotes_runtime(0);
}
?>

 

*note* NOT MY SCRIPT, can't remember where it came from, but it is in my library.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.