HTML POST方法下載對應的php

HTML POST方法下載對應的php

我正在 HTML 上製作一個身份驗證表單,並嘗試將其與 PHP 連結。 HTML 程式碼是

<!DOCTYPE html>
<html>
<head>
    <title>Authorized logged in</title>
</head>

<div id = "adminBoard">

<form method = "POST" action = "auth.php">
<input type="text" class = "credentialInputL" name="loginInput" value = "login" size = 30>
<input type="password" class = "credentialInputP" name="passwordInput" value = "pass" size = 30>
<input class="loginLogoutButton" type = "submit" value = "Sign in" name="loginLogout">
</form>
</div>

</body>
</html>

相應的 auth.php 檔案(我在擴展它之前確保 POST 方法的基本工作)是:

<?php
    if (isset($_POST['loginInput']) && isset($_POST['passwordInput'])){
        $username = $_POST['loginInput'];
        $password = $_POST['passwordInput'];
        echo "The username is :" . $username;
        echo "The password is :" . $password;
    }
?>

但是,當我在 Chrome 中開啟 HTML 檔案並點擊「登入」按鈕時,就會下載 auth.php 檔案。沒有任何操作發生。 html 和 php 檔案都位於同一資料夾中。

我是否缺少一些語法/運算符/方法?

答案1

當 Web 伺服器無法識別文件類型時,它傾向於下載而不是執行。

首先確保您已經安裝並啟用了 php5module。您可以從命令列檢查:

$ a2enmod -l

操作別名 auth_basic authn_file authz_host authz_groupfile authz_user autoindex cgi dir env 過期包括 log_config mime 協商 setenvif ssl socache_shmcb userdir reqtimeout authn_core mcrypt mod_rewritephp5authz_core

然後也要檢查您的 httpd.conf 或 default-server.conf 並確保它包含新增類型

文檔根目錄“/srv/www/htdocs”

DirectoryIndexindex.htmlindex.htmindex.phpindex.php5index.php4index.php3

AddType 應用程式/x-httpd-php .php .php3 .php4 .php5

不要忘記重新啟動 Ubuntu 的 Web 伺服器: sudo service apache2 restart

相關內容