2006年06月14日

magic_quotes_gpc

データベースに格納した、フォームからの入力データの「'」や「"」が、「\」マークでエスケープされてしまうとの指摘。

調べてみると、PHPには、これらのデータを自動的にエスケープする機能があり、デフォルトで有効になっているとのこと。

次のように設定を変更。

# vi /etc/php.ini
magic_quotes_gpc = Off


解決・・・かと思いきや、今度はPostfix Adminが動かなくなってしまった。

該当箇所を調べてみると、

/srv/www/htdocs/postfixadmin/functions.inc.php
function escape_string ($string)
{
global $CONF;
if (get_magic_quotes_gpc () == 0)
{
if ($CONF['database_type'] == "mysql")
$escaped_string = mysql_real_escape_string ($string);

if ($CONF['database_type'] == "mysqli")
$escaped_string = mysqli_real_escape_string ($string);
if ($CONF['database_type'] == "pgsql")
$escaped_string = pg_escape_string ($string);
}
else
{
$escaped_string = $string;
}
return $escaped_string;
}


はは〜ん、これは恐らく、DBにコネクト前にmysql_real_escape_string()を呼び出したエラーだな、とピンと来た。自分がよくやるので。

調べてみると、このバグは既に報告されていた。

#55 (function escape_string dont work if magic_quote_gpc is deactivated) - Postfix Admin - Trac

このページに倣って、以下のようにコードを2箇所、変更。

# vi /srv/www/htdocs/postfixadmin/functions.inc.php
function escape_string ($string)
{
global $CONF;
if (get_magic_quotes_gpc () == 0)
{
$link = db_connect ();
if ($CONF['database_type'] == "mysql")
$escaped_string = mysql_real_escape_string ($string);
if ($CONF['database_type'] == "mysqli")
$escaped_string = mysqli_real_escape_string ($link, $string);
if ($CONF['database_type'] == "pgsql")
$escaped_string = pg_escape_string ($string);
}
else
{
$escaped_string = $string;
}
return $escaped_string;
}


解決。

(追記)
<pre>タグ使うと、自動改行されなくなるのか・・・知らなかった。
上記のソースの適当なところで、改行を挿入。


posted by Wait-and-See at 20:44 | Comment(2) | TrackBack(0) | PHP/MySQL
この記事へのコメント
magic_quotesってほんっといろんなところでトラブル起こしてくれますよね
Posted by at 2009年02月09日 23:54

明るい未来を信じよう♪
暗い日常は自ら切り開くモンだぜ?
http://3thoal4.plistfa.info/
Posted by ちょっとした暇でもヤれる♪ at 2011年03月21日 06:03
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

この記事へのトラックバックURL
http://blog.seesaa.jp/tb/19223235

この記事へのトラックバック