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

하지만 크롬에서 HTML 파일을 열고 로그인 버튼을 클릭하면 auth.php 파일이 다운로드됩니다. 아무 작업도 수행되지 않습니다. html과 php 파일은 모두 같은 폴더에 있습니다.

일부 구문/연산자/메서드가 누락되었나요?

답변1

웹 서버는 파일 형식을 인식하지 못하면 실행하지 않고 다운로드하는 경향이 있습니다.

먼저 php5module을 설치하고 활성화했는지 확인하십시오. 명령줄에서 확인할 수 있습니다.

$ a2enmod -l

작업 별칭 auth_basic authn_file authz_host authz_groupfile authz_user autoindex cgi dir env 만료 include log_config MIME 협상 setenvif ssl socache_shmcb userdir reqtimeout authn_core mcrypt mod_rewritePHP5authz_core

그런 다음 httpd.conf 또는 default-server.conf를 확인하고 포함되어 있는지 확인하십시오.유형 추가

DocumentRoot "/srv/www/htdocs"

디렉토리색인 index.html index.htm index.php index.php5 index.php4 index.php3

AddType 애플리케이션/x-httpd-php .php .php3 .php4 .php5

Ubuntu용 웹 서버를 다시 시작하는 것을 잊지 마세요: sudo service apache2 restart

관련 정보