8

bluehost をウェブホストとして使用していますが、いくつか問題があります。以下のコードは、私の混乱のポイントです。

<?php
include '../init.php';
error_reporting(0);
?>
<div class='container'>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/bootstrap/css/responsive.css">    
<link rel="stylesheet" type="text/css" href="/bootstrap/css/responsive.min.css">
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="SignIn.css">
<title>SoundBooth - Sign in</title>
<link rel="icon" href="../Images/Logo.png" type="image/x-icon"/>
</head>
<body  background="../Images/BGMain.png">
<div class='signinLabel'>Sign in</div>
<div class='bg'></div>
<div class='user'>Username</div>
<div class='pass'>Password</div>
<form action="index.php" method='POST'>
  <input name='Username' autocomplete="off"class='usr' type="text" style='height:34px;'/>
  <input name='Password' autocomplete="off"class='pas'type="password" style='height:34px;'/>

  <input type='submit' class='submit' value='Log in' ></input>
</form>
<a class='forgotPass' href="#">(Forgot password)</a>
<div class='no-account-label'>Don't have an account? |</div>
<a class='no-account-button' href="/signup">Sign up</a>
<?php
 if (empty($_POST) === false){
    $username = $_POST['Username'];
    $password = $_POST['Password'];

    if (empty($username) || empty($password)){ ?>
            <div style="float:left;margin:-415px 200px;width:500px;text-indent:100px;"class="alert alert-error">You need to enter a username and password!</div>
            <?php
        }elseif (user_exists($username) === false){?>
            <div style="float:left;margin:-415px 170px;width:500px;text-indent:100px;"class="alert alert-error">We can't find that username! Have you <a style='color: rgb(185, 74, 72);' href='../HTML/signup.html'>registered?</a></div>
            <?php
        }elseif (user_active($username) === false){ ?>
            <div style="float:left;margin:-415px 200px;width:500px;text-indent:100px;"class="alert alert-error">You haven't activated your account!</div> <!--Remove this-->
            <?php
        }else{

            $login = login($username, $password);
            if ($login === false){ ?>
            <div style="float:left;margin:-415px 200px;width:500px;text-indent:100px;"class="alert alert-error">The username or password you have entered is incorrect!</div>
            <?php
            }else{
                $errors[] = 'Logging In...';
                $_SESSION['user_id'] = $login;
                if (isset($_SESSION['user_id'])){
                mysql_query("UPDATE `users` SET `online_offline`='1' WHERE `user_id`='$_SESSION[user_id]'");
                }
                header("Location: http://sound-booth.com/");
                exit();
            } 
        }
    }
    echo output_errors($errors)
?>
</div>
</body>
</html>

スクリプトへのリンクです。ローカルホストでは機能しますが、実際のサーバーでは機能しません。header() リダイレクトでさえ機能しません。

誰かがこれを説明してもらえますか?

解決:

ob_start();
4

11 に答える 11

9

最良のオプションは、このように使用することです。

// Use this line instead of header
echo "<script>location='your_url.com'</script>";
于 2015-02-20T08:02:21.337 に答える
7

出力を送信する前にヘッダーを設定する必要があります。header()その呼び出しを行う前に、ユーザーに大量の HTML を送信しています。おそらく、ある環境では機能しますが、別の環境では機能しないためoutput_buffering、localhost php.ini に設定されていますが、サーバーには設定されていません。

が送信される前にコードを修正する必要がありますが、コードの先頭にheader()追加して機能させたい場合はob_start()、バッファリングが強制されます。

于 2013-03-14T00:09:03.190 に答える
4

ob_start();ドキュメントの直後<?phpと最後に使用し ob_end_flush();ます。

于 2015-07-15T06:14:01.913 に答える
2

HTTP headers must be sent before the HTTP response. I.e., you must call header before echoing anything else or sending any HTML.

Chances are, the reason it works on your local server is because you have configured output buffering there. You can insert a call to ob_start(); at the top of the page to enable output buffering within the script. Then, since the HTML will be buffered until the script is done, the redirect header can get to the browser first, as it must. Or, you can rework the script to put the header call at the top.

于 2013-03-14T00:07:25.093 に答える
1
header("Location: http://sound-booth.com/");

it goes after text output.

Use OB_start() or change your code.

于 2013-03-14T00:07:55.610 に答える
0

OP、

開始タグの<div class='container'> 前にあります<html>(その後、前に閉じられ</body>ます。

タグ<div class='container'>を開いてから移動してみてください。<body>

お役に立てば幸いです。

于 2013-03-14T00:11:53.753 に答える
0

You probably have your error reporting turned off which is why you won't get an error message.

header() does not work if you have even a white space before it. You would need to put it above all your string outputs in order for it to work.

于 2013-03-14T00:06:09.757 に答える
0

私は同じ問題に直面しています。最後の答えがうまくいきました。

echo "location=' https://mysiteurl.in '";

Jon Surrell に感謝します。Session Values も含まれています。

于 2015-03-26T23:57:20.780 に答える