簡體   English   中英

我的PHP在本地工作,但不在1and1服務器上

[英]My PHP is working locally, but not on 1and1 server

我已經在計算機上本地測試了以下腳本,並且一切都能按我想要的方式完美運行。 但是,當我將文件上傳到服務器上的1and1位置時,單擊“提交”按鈕時,在登錄腳本上,它僅停留在登錄屏幕上。

我也不確定,但是也許問題不在於會話,而在於我的標頭函數。

<?php
    session_start();
    require ("login.php");
    include ("header.php");
    include ("subnav.php");

    if ((isset($_SESSION['user'])) && (isset($_SESSION['admin'])))
        header('Location: admin/index.php' );

    if ((isset($_SESSION['user'])) && (!isset($_SESSION['admin'])))
        header('Location: customer/index.php' );

    if ((isset($_GET['logout'])) == 1) {
        session_destroy();
        header('Location: index.php');
    }

    if (isset($_POST['submit'])) 
        if($_POST['username'] == 'jay') {
            $_SESSION['user'] = 'jay';
            $_SESSION['admin'] = 1;
            header('Location: admin/index.php' );
        }
        else if ($_POST['username'] == 'william'){
            $_SESSION['user'] = 'william';
            header('Location: customer/index.php' );
        }
        else {
            header('Location: http://www.google.com' );
        }
?>

    <h2>System Log-In</h2>

    <form action="" method="post">
        <ul id="login">
            <li>
                Username: <br>
                <input type="text" name="username"></li>
            <li>
                Password: <br>
                <input type="password" name="password">
            </li>
            <li>
                <input type="submit" value="Log-In" name ="submit" id="submit">
            </li>
            <li>
                <br><a href=#>Register Here.</a>
            </li>
            <li>
                If you are having problems with the log-in process, please send us an <a href="mailto:here@here.us">e-mail</a>.
            </li>
        </ul>
    </form>


<?php   
    include ("footer.php");
?>

在此處輸入圖片說明

將大括號放在代碼中的這一點上,以正確完成代碼塊:

if( isset( $_POST['submit'] ) )

通常,最好對所有if語句始終使用花括號,即使它們只是一行。 這有助於防止此類混亂問題。

它可能有幫助,也可能沒有幫助,但您應該按照以下順序進行操作:

  1. 使用Location:標頭時,應始終使用die()終止腳本。 否則,腳本的其余部分將繼續運行: header('Location: ...'); die; header('Location: ...'); die;

  2. 同樣與Location:標頭有關,您確實應該在路徑的前面加一個斜杠。 例如, Location: /index.php

  3. 我希望該代碼可供練習。 僅基於POST變量的值來授予用戶admin狀態並不十分安全。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM