简体   繁体   中英

PHP Files shown as Plaintext in Apache2 LAMP Machine

I have a PHP+HTML file in my Ubuntu LAMP machine. I recently cleaned up the project files from /var/www/html/ as I though I have done with that project. Although today I wanted to check something so I get the project folder from dropbox account back to html directory.

The problem is that when I type the url of localhost I get the HTML structure as plaintext. Why suddenly I came up with that problem? I have graded access to my html folder already and haven't touch anything after I removed the project folder from that dir.

Just to point out, the online version of the project hosted in a webserver works fine.

My index.php file :

<?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>

An Image of what I see in my broswer :

在此处输入图片说明

RIP GUYS.

I just show it. I set the header to text/plain .

If you remove the header all works fine:

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

..or if we change it to text/html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM