简体   繁体   English

无法 POST /file.php

[英]Cannot POST /file.php

I'm having a problem with php , the problem is I only get Cannot POST /file.php error after I click submit button.我在使用php 时遇到问题,问题是我在单击提交按钮后只会收到无法 POST /file.php错误。 I'm using LAMPP and activate the webserver service , and I've place my project into /htdocs folder, but its still the same.我正在使用 LAMPP 并激活webserver 服务,并且我已将我的项目放入 /htdocs 文件夹中,但它仍然相同。

this is my code: html这是我的代码:html

<form id="flogin" method="post" action="phpe.php"> <!--form login-->
<input id="user" name="user" placeholder="username" type="text">
<input id="pass" name="pass" placeholder="password" type="password"><br>
<input id="bf" type="submit" value="login">
</form>

phpe.php: phpe.php:

<?php
$username="singduwe";
$password="websiteiki";

if($_POST["user"]==$username and $_POST["pass"]==$password){
    session_start();
    $_SESSION["admin"]="yes";
    header("location:admin.php");
}else{
    session_start();
    $_SESSION["admin"]="no";
    header("location:index.html");
}

?>

admin.php:管理.php:

<?php
session_start();

?>

<html>
<head></head>
<body>
    hi</body>
</html>

update I'm using Brackets code editor更新我正在使用 Brackets 代码编辑器

Gave your code a quick try and it works as expected.快速尝试一下您的代码,它按预期工作。 May be you are missing something in your setup?可能是您在设置中遗漏了什么? what is exact error message?什么是确切的错误信息?

It looks to me like your webserver does not have PHP installed?在我看来,您的网络服务器没有安装 PHP?

How did you install your LAMP stack?您是如何安装 LAMP 堆栈的? Since you said LAMP, i am assuming your server is linux.既然你说 LAMP,我假设你的服务器是 linux。

Please check if php is installed on your server, if it is, is Apache configured to use PHP?请检查您的服务器上是否安装了 php,如果安装了,Apache 是否配置为使用 PHP?

It is rather easy to install using yum or apt-get, based on your linux installation.根据您的 linux 安装,使用 yum 或 apt-get 进行安装相当容易。 Take a look at this https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu看看这个https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

To do a quick check if php is installed, create a test file with要快速检查是否安装了 php,请创建一个测试文件

<?PHP 
 phpinfo();
?>

If everything is well, you should see a bunch of PHP information...something like this如果一切顺利,你应该会看到一堆 PHP 信息……像这样

http://i.imgur.com/L0eospD.png http://i.imgur.com/L0eospD.png

Your code is pretty straight forward and should not fail unless your setup is wrong.您的代码非常简单,除非您的设置有误,否则不会失败。 If you are windows user, try a locally hosted WAMP server;如果您是 Windows 用户,请尝试使用本地托管的 WAMP 服务器; that will be helpful if you do not wish to fiddle with Linux.如果您不想摆弄 Linux,这将很有帮助。

Can you try to edit action="phpe.php" to action="yourdirectory/phpe.php"您可以尝试将action="phpe.php"编辑为action="yourdirectory/phpe.php"

It may work.它可能会起作用。 If it'll still same, please give me more details.如果它仍然相同,请给我更多详细信息。

Ensure your php file path is included in the portion of the code you are calling it.确保您的 php 文件路径包含在您调用它的代码部分中。 Sound like the project is not stored in the default htdocs folder.听起来项目没有存储在默认的 htdocs 文件夹中。 Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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