PHP文件在Apache2 LAMP Machine中显示为纯文本

时间:2016-01-10 12:34:01

标签: php apache lamp

我的Ubuntu LAMP机器上有一个PHP + HTML文件。我最近清理了/var/www/html/中的项目文件,因为我已经完成了该项目。虽然今天我想检查一下,所以我将项目文件夹从dropbox帐户返回到html目录。

问题是,当我输入localhost的网址时,我将HTML结构视为纯文本。为什么我突然想出那个问题?我已经评估了对html文件夹的访问权限,并且在我从该目录中删除了项目文件夹后,我无法触摸任何内容。

需要指出的是,在网络服务器中托管的项目的在线版本可以正常工作。

我的index.php文件:

<?php
session_start();
header('Content-type: text/plain; charset=utf-8');
    if(isset($_SESSION['login'])) {
      header('Location: home.php');
    }
    require_once 'lib/config.php';

    $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_DATABSE, $conn);

    if(isset($_POST['register-button'])) {
        $UserEmail =  mysql_real_escape_string($_POST['Remail']);
        $Pass1 =  mysql_real_escape_string($_POST['RPass1']);
        $Pass2 =  mysql_real_escape_string($_POST['RPass2']);

        if ($Pass1 == $Pass1) {
            $qr = mysql_query("SELECT * FROM Users WHERE UserEmail = '".$UserEmail."'");
            $row = mysql_num_rows($qr);
            if($row > 0){
                echo "<script type='text/javascript'>alert('Email already registered');</script>";
            }
            else {

                /*$cost = 10;
                $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
                $salt = sprintf("$2a$%02d$", $cost) . $salt;
                $PassHash = crypt($Pass1, $salt);*/

                mysql_query("INSERT INTO Users(UserEmail, UserPass) values('".$UserEmail."','".$Pass1."')") or die(mysql_error());

                /*$UserId =  mysql_insert_id();
                $sql = "UPDATE MyGuests SET UserId='".$UserId."' WHERE id=".$UserId."";
                mysql_query($conn, $sql);
                */
            }
        }
    }
    if(isset($_POST['login-button'])) {
        $UserEmail =  mysql_real_escape_string($_POST['Lemail']);
        $Pass =  mysql_real_escape_string($_POST['LPass']);
        $result = mysql_query("SELECT UserPass FROM Users WHERE UserEmail = '".$UserEmail."'");
        if (!$result) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        $row = mysql_fetch_row($result);
        if ($Pass == $row[0]) {
            $_SESSION['login'] = $UserEmail;
            header("location:home.php");
        }
    } 

?>
<!DOCTYPE html>
<html>
<head>
    <title>Secreat Sea</title>

    <link rel="stylesheet" type="text/css" href="index.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</head>
<body>

<div class="wrapper">
    <div class="welcome-container">
    <div class="Logo">
            <img src="img/Lovelogo.svg" >
        </div>
        <div class="header">
            <h2>&nbsp;Welcome to SecretSea</h2>
        </div>

        <div class="informations">
            <p style="padding-left: 0px; padding-right: 0xp; padding-bottom: 10px; font-family: Lato;" id="p1">
                An Strictly Two-Side Communication App
            </p>
            <p style="padding-bottom: 30px; font-family: Lato;" id="p2">For people who love each other's &#9829</p>

            <form id="login" method="POST">

                <input name="Lemail" placeholder="Your Username" required="required" type="text">
                <input name="LPass" placeholder="Password" required="required" type="password">
                <button type="submit" id="login-button" name="login-button">Dive</button>

            </form>

            <form id="register" method="POST">
                <input id="Remail" name="Remail" placeholder="Your email" required="required" type="email" autocomplete="off">
                <input id="RPass1" name="RPass1" placeholder="Your Password" required="required" type="password" autocomplete="off">
                <input id="RPass2" name="RPass2" placeholder="Your Password" required="required" type="password" autocomplete="off">

                <button type="submit" id="register-button" name="register-button">Register</button>
            </form>

            <div style="padding-top: 10px;"></div>

            <div class="GetStarted" id="GetStarted">
                <a href="#">Get Started Today</a>
            </div>
            <div class="LearnMore" id="LearnMore">
                <a href="#">Learn More</a>
            </div>



            </div>

            <div class="footer">
                <div class="copyright">Copyright GeorgeGkas 2015-2016</div>
            </div>
    </div>
</div>

</body>
</html>

我在broswer中看到的图像:

enter image description here

1 个答案:

答案 0 :(得分:0)

RIP GUYS。

我只是展示它。我将标题设置为text/plain

如果删除标题,一切正常:

header('Content-type: text/plain; charset=utf-8');

..或者如果我们将其更改为text/html