2

データベースやセッションを含まない私のコードは完璧な結果をもたらします

<!DOCTYPE html>
<?php
if(isset($_GET["engine"]))
{
if($_GET["engine"]=="google")
header("Location:http://www.google.com/search?q=".$_GET["q"]);
elseif($_GET["engine"]=="yahoo")
header("Location:http://search.yahoo.com/search?q=".$_GET["q"]);
if($_GET["engine"]=="bing")
header("Location:http://www.bing.com/search?q=".$_GET["q"]);
}
?>
<html>
<head>
<title>Fake search</title>
</head>
<body>
<form action="fakeSearch.php" method="GET">
<input type="text" name="q" value=""/><br/>
Google <input type="radio" name="engine" value="google"/><br/>
Yahoo <input type="radio" name="engine" value="yahoo"/><br/>
Bing <input type="radio" name="engine" value="bing"/><br/>
<input type="submit"/>
</form>
</body>
</html>

しかし、ログインページを作成し、セッション変数を使用して上記と同じコードを持つhome.phpにリダイレクトすると、オブジェクトが見つかりませんというエラーが表示されます!

 The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. 

 If you think this is a server error, please contact the webmaster. 
Error 404
localhost
Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

これがコードです

<?php
session_start();
if(isset($_SESSION["authenticated"]))
{
if($_SESSION["authenticated"]==TRUE)
?>
<!DOCTYPE html>
<html>
<head><title>Home</title></head>
<body>
<a href="logout.php">Logout</a>
<?php
if(isset($_GET["engine"]))
{
if($_GET["engine"]=="google")
header("Location:http://www.google.com/search?q=".$_GET["q"]);
elseif($_GET["engine"]=="yahoo")
header("Location:http://search.yahoo.com/search?q=".$_GET["q"]);
if($_GET["engine"]=="bing")
header("Location:http://www.bing.com/search?q=".$_GET["q"]);
}
?>
<form action="fakeSearch.php" method="GET">
<input type="text" name="q" value=""/><br/>
Google <input type="radio" name="engine" value="google"/><br/>
Yahoo <input type="radio" name="engine" value="yahoo"/><br/>
Bing <input type="radio" name="engine" value="bing"/><br/>
<input type="submit"/>
</form>
</body>
</html>
<?php }
else{
header("Location:login.php.");
}?>
4

3 に答える 3

0

リダイレクトの最後に余分なピリオドがあります。代わりにこれを試してください:

header("Location:login.php");
于 2013-07-11T04:42:18.460 に答える
0

フォーム アクションでは、fakesearch.php を使用しています

<form action="fakeSearch.php" method="GET">

しかし、あなたは同じファイルにアクションコーディングを書いています

if(isset($_GET["engine"]))
{
if($_GET["engine"]=="google")
header("Location:http://www.google.com/search?q=".$_GET["q"]);
elseif($_GET["engine"]=="yahoo")
header("Location:http://search.yahoo.com/search?q=".$_GET["q"]);
if($_GET["engine"]=="bing")
header("Location:http://www.bing.com/search?q=".$_GET["q"]);
}

送信ボタンをクリックすると、fakesearch.php ファイルが検索されます。

form タグの action 属性に「#」を使用するか、空にしてみてください。

<?php
session_start();
if(isset($_SESSION["authenticated"]))
{
if($_SESSION["authenticated"]==TRUE)
?>

body タグの後にこのコードを挿入してみてください

  if($_SESSION["authenticated"]==TRUE)  {

開いた中括弧が欠落していると思います。(@ Orangepil からのアイデア)

ではごきげんよう!

于 2013-07-11T04:40:08.043 に答える
0

おそらく、「Location:login.php」の「php」の後の末尾のピリオドです。

于 2013-07-11T04:40:19.813 に答える