考虑下面的PHP代码:新手PHP的编码问题:头功能(也许,我需要有人来检查我的代码)
<?php
$searchsport = $_REQUEST['sport'];
$sportarray = array(
"Football" => "Fb01",
"Cricket" => "ck32",
"Tennis" => "Tn43",
);
header("Location: ".$sportarray[$searchsport].".html"); //directs user to the corresponding page they searched
if ($searchsport == NULL) {
header("Location: youtypednothing.html"); //directs user to a page I've set up to warn them if they've entered nothing
} else {
header("Location: sportdoesnotexist.html"); //if sport isn't in my root, a warning will appear
}
?>
我觉得代码中的注释是不言自明的,基本上当我输入网球场我的form.html它会发送数据到这个php文件并处理,并指导我Tn43.html这是我的网球页面。不幸的是,它不起作用,我真的想知道为什么......(我知道我犯了一个非常愚蠢的错误)。
PS:头是正确的功能,当做一些重定向?
好的,另外一个问题是,这种形式是否有可能被一些坏的屁股攻击呢? – Haskella 2010-05-23 06:10:27