簡體   English   中英

頁面在本地主機上運行良好但未在托管服務器上運行

[英]Pages are working fine on localhost but not running on the hosting server

我創建了一個 PHP 網站,它在我的本地主機上運行良好,但是當我在服務器上上傳相同的代碼時,它在服務器上顯示空白頁面。

我懷疑的問題是在我的代碼中的任何地方我使用了數據庫連接( dbc.php )我的頁面變得空白。 當我刪除該數據庫連接代碼時,一切正常。

我正在輸入登錄代碼和 dbc.php。

我的登錄密碼.php

<?php


include('dbc.php');


 // get form data, making sure it is valid
 $phone = mysql_real_escape_string(htmlspecialchars($_POST['id']));
 $pass = mysql_real_escape_string(htmlspecialchars($_POST['password']));

 // check to make sure both fields are entered
 if ($phone == '' || $pass == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 // if either field is blank, display the form again
header("Location: " .$_SERVER['HTTP_REFERER']);
 } 
 else
 {
 // save the data to the database

    $login_sql=mysql_query("select * from member where email='$phone' and  password='$pass'")
    or die(mysql_error()); 
    $num=mysql_num_rows($login_sql);

    if($num>0)
    {
     session_start();
     $admin_data=mysql_fetch_array($login_sql);
     $_SESSION['usermatri_id']=$admin_data['mid'];


        if($admin_data['mid']>0)
            {
                 header("Location: dashboard.php"); 

            }
        else 
            {
                header("location:".$_SERVER["HTTP_REFERER"]);
            }

     exit;
     }
 else{

    header("location:".$_SERVER["HTTP_REFERER"]);
 }
 }



  // if the form hasn't been submitted, display the form


?>

我的 dbc.php 代碼

<?php
//connection to the database
mysql_connect("localhost","root","")or die(mysql_error('cannot connect'));
mysql_select_db("matrimony");
?>

1)我試過這些問題,但沒有運作

PHP 在服務器上不工作

PHP 重定向在服務器上不起作用

2) 我也嘗試添加錯誤檢查,網頁上沒有顯示任何內容,甚至嘗試查看 cPanel 錯誤日志。

ini_set('display_errors',1); 
 error_reporting(E_ALL);

第一的

下面的代碼是方式,方式錯誤...

 if ($phone == '' || $pass == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 // if either field is blank, display the form again
header("Location: " .$_SERVER['HTTP_REFERER']);
 } else{
//the juice...
}

以上意味着如果:

$_POST['id'] = 123456;
$_POST['password'] = 123456;

我還能喝“果汁


第二:

a) 確保 MySql 服務器已啟動並正在運行。
b) 確保您嘗試訪問的數據庫和表已正確導入。
c) 還要確保您有權訪問該特定數據庫。


第三:

從小處着手

只需將以下內容添加到您的腳本中:

ini_set('display_errors',1); 
error_reporting(E_ALL);

mysql_connect("localhost","root","")or die(mysql_error('cannot connect'));
mysql_select_db("matrimony");

任何錯誤? 不,很好,繼續添加小段代碼,直到你找到造成你生命中浪費的 3 天的原因。

嘗試以上方法后,我將重復自己,嘗試以上方法后如果仍有問題,請在我的答案下方評論,我會盡力幫助您。

mysql_real_escape_string函數從 PHP 4.3.0 開始被棄用,將來會被移除。在最新版本的 PHP 中它會拋出警告消息。如果在header函數之前的頁面中會打印任何消息(文本/警告/錯誤),那么它不會重定向。

可能是這里不允許建立與DB的連接。您可以使用mysqli函數進行相同的操作。

我認為@Pedro Lobito 很好地解釋了所有可能的問題,您應該考慮按照他的建議逐步執行此操作。

但現在你可以嘗試編輯你的

登錄.php

像這樣,我希望這會有所幫助,但也嘗試@Pedro 回答。

<?php
 $mail = $_POST['id'];
 $pass = $_POST['password'];
// check to make sure both fields are entered
 if ($mail == '' || $pass == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 // if either field is blank, display the form again
header("Location: " .$_SERVER['HTTP_REFERER']);
 } 
else 

{
         include('dbc.php');
         $sql=mysql_query("SELECT * from member where email='$mail' and  password='$pass'")or die(mysql_error());
         $num=mysql_num_rows($sql);
         if($num>0)
     {
               $admin_data=mysql_fetch_array($sql);
           session_start();
           $_SESSION['usermatri_id']=$admin_data['mid'];

           header("Location: dashboard.php");    

        }
     else 
     {
        header('Location:' . $_SERVER['PHP_SELF']);
     }


}

?>

歡迎使用 Stackoverflow。

    //index.php
<?php
$conn = mysqli_connect("localhost","root","","md5login");
session_start();

if (isset($_SESSION["Email"]))
{
    header("location:welcome.php");
}
if (isset($_POST["register"]))
{
    if (empty($_POST["Email"]) && empty($_POST["Password"]))
    {
        echo '<script>alert("Both Field Are Required")</script>';
    }
    else
        {
        $Email = mysqli_real_escape_string($conn, $_POST["Email"]);
        $Password = mysqli_real_escape_string($conn, $_POST["Password"]);
        $Password = md5($Password);
        $query = "INSERT INTO client (Email, Password) VALUES('$Email','$Password')";
        if (mysqli_query($conn, $query))
        {
            echo '<script>alert("Rgistration Done")</script>';
        }
    }
}
    if (isset($_POST["login"]))
    {
        if (empty($_POST["Email"]) && empty($_POST["Password"]))
        {
          echo '<script>alert("Both r Required")</script>';
        }
        else
        {
            $Email = mysqli_real_escape_string($conn, $_POST["Email"]);
            $Password = mysqli_real_escape_string($conn, $_POST["Password"]);
            $Password = md5($Password);

            $query = "SELECT * FROM client WHERE Email = '$Email' AND Password = '$Password'";
            $result = mysqli_query($conn, $query);

            if (mysqli_num_rows($result) > 0)
            {
                $_SESSION['Email'] = $Email;
                header("location:welcome.php");

            }
            else
            {
                echo '<script>alert("Wrong User Details")</script>';
            }
        }
    }

?>
<html>
<head>
    <title>Login And Registeration</title>
</head>
<body>
<div class="container" style="width:500px;">
<h3 align="center"> Login And Register </h3>
    <br>
    <?php
    if (isset($_GET["action"]) == "login")
    {
    ?>
    <h3 align="center">Login</h3>
    <br>
        <form method="post">
            <label>Enter Email</label>
            <input type="text" name="Email">
            <br/>
            <label>Enter Password</label>
            <input type="text" name="Password">
            <br/>
            <input type="submit" name="login" value="Login">
            <br/>
            <p align="center"><a href="index.php">Register</a></p>
        </form>
    <?php
    }
    else
    {
    ?>
        <h3 align="center">Register</h3>
        <br>
        <form method="post">
            <label>Enter Email</label>
            <input type="text" name="Email">
            <br/>
            <label>Enter Password</label>
            <input type="text" name="Password">
            <br/>
            <input type="submit" name="register" value="register">
            <br/>
            <p align="center"><a href="index.php?action=login">Login</a></p>
        </form>
    <?php
    }
    ?>


</div>
</body>
</html>

//welcome.php
<?php
session_start();
if (!isset($_SESSION["Email"]))
{
    header("location:index.php?action=login");
}
?>
<html>
<head>
    <title>Welcome Page</title>
</head>
<body>
<?php
echo '<h2>Welcome - '.$_SESSION["Email"].'</h2>';
echo '<a href="logout.php">Logout </a>';
?>

</body>
</html>

//logout.php

<?php
session_start();
session_destroy();
header("location:index.php?action=login");
?>

我遇到了這個問題,我幾乎流下了眼淚。 當我承諾分享鏈接時,客戶正在等我。 現在要解決這個問題,您需要進行一些故障排除:

  1. 檢查您是否正確加載了所有cssjs文件。 確保。

  2. css文件中刪除注釋。 很重要。

  3. 更新 jquery。 如果可能,請使用 CDN。 不要使用 slim 因為某些函數會拋出錯誤。

  4. 如果密碼和所有正確,請檢查數據庫連接。

  5. 檢查您的 php 文件是否有錯誤將以下內容放在您的標題 php 標簽中

    ni_set('display_errors', 1); ini_set('display_startup_errors', 1); 錯誤報告(E_ALL);

就我而言,它是 jquery 文件不起作用和 css 文件中的注釋。 還加載不在目錄中的文件,例如說 href="assets/css/main.css" 而它不在那里。

如果我對你的問題的理解正確。 首先,您必須編輯 dbc.php。 因為用戶名、密碼和數據庫名稱與“本地主機”(XAMPP) 中的值不同。 這可能是網站空白的原因,但在本地主機上工作正常。

當您在您的域中創建 mysqldatabase 時,它會要求您使用“強密碼”創建“用戶”,並且不能為“空白”。 因此,您必須在 dbc.php 中輸入“正確的值”,並在域/子域設置中輸入“相同的值”。 如果這已經完成,那么我們可以 go 進行下一個問題跟蹤。

暫無
暫無

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

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