昨日のはまり(sqlite_escape_string のバグにはまる (groundwalker.com))で思い出したので、はまりネタでもうひとつ。リダイレクトしない罠
(本当は違うコードだけど出せないので)たとえば、文字列を逆順にするだけの簡単なアプリを作る。
revtext.php
<?
if ($_POST) {
require_once('my_module.php');
$my_text=revtext($_POST['my_text']);
require_once('HTTP.php');
HTTP::redirect('revtext.php?my_text='.urlencode($my_text));
}
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head><title>Reverse Text</title></head>
<body>
Reverse Text Sample
<form action="revtext.php" method="POST">
<input type="text" name="my_text" value="<? echo $_GET['my_text'] ?>">
<input type="submit" value="Reverse">
</form>
</body>
</html>
で、読み込んでいる my_module.php
<?
function revtext($text)
{
preg_match_all('/./u',$text,$result);
return implode(array_reverse($result[0]));
}
?>
で、本来なら、revtext.php に POST されて、逆順の文字列を生成して、パラメータにつんで、自分自身にリダイレクトする。。。。はずなのだがしない。うーん。
でまぁ、こういう場合はだいたい HTTPのヘッダを出力する前になんか出力しまっているせいが多いのだが、見つからないときは見つからないもので。結局、
groundwalker.com