获取密码后运行函数

发布于 2024-10-03 00:45:25 字数 307 浏览 0 评论 0原文

我们有脚本 http://site.com/ourscript.php

如何添加类似“输入密码”块在该页面上?

只是一些简单的,也许是弹出窗口。

就像,我们在浏览器中打开页面,我们应该输入密码,如果可以的话 - 函数将运行。

它只能在请求的 php 文件内完成,不应使用 .htaccess

谢谢。

We have script http://site.com/ourscript.php

How to add something like "enter password" block on that page?

Just some simple, maybe popup.

Like, we open the page in browser, we should type password, if its ok - function will run.

It has to be done only inside requested php file, .htaccess should not be used.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫以 2024-10-10 00:45:25

这很简单:

<html>
    <body>

<?php if (isset($_POST['secret']) && $_POST['secret'] == "lolsecurity") { ?>

        <h1>Secret Page!</h1>
        <p>This type of password-protection is completely open to packet sniffing.</p>

<?php } else { ?>

        <form method="POST">
            <p>Enter Password:</p>
            <input type="password" name="secret">
            <input type="submit" value="Submit">
        </form>

<?php } ?>

    </body>
</html>

This is about as simple as it gets:

<html>
    <body>

<?php if (isset($_POST['secret']) && $_POST['secret'] == "lolsecurity") { ?>

        <h1>Secret Page!</h1>
        <p>This type of password-protection is completely open to packet sniffing.</p>

<?php } else { ?>

        <form method="POST">
            <p>Enter Password:</p>
            <input type="password" name="secret">
            <input type="submit" value="Submit">
        </form>

<?php } ?>

    </body>
</html>
秋风の叶未落 2024-10-10 00:45:25

这是教程一个基本的身份验证系统。我确信如果您花两分钟谷歌搜索,您会发现大约一百万个预制的、现成的 PHP 登录系统。

如果您想创建自己的用户,则对用户进行身份验证通常需要执行以下操作:

  • 首先在数据库中设置一个用户表,在其中存储有效的用户名及其密码(以及任何其他相关的用户信息)。密码不应以纯文本形式存储,而通常应经过加盐处理和哈希处理。
  • 将登录表单添加到您的应用程序中。当用户成功登录时(您可以通过获取给定的密码、如上所述对其进行加盐和散列并将其与数据库中的值进行比较来确定),使用 cookie 或会话来跟踪登录令牌。
  • 在每个需要身份验证的页面上,都应该验证登录令牌。如果登录令牌无效或未提供登录令牌,则重定向到登录表单。

Here's a tutorial for a basic authentication system. I'm sure if you spend two minutes googling, you'll find about a million pre-made, ready-to-go PHP login systems.

If you want to create your own, authenticating a user generally requires the following:

  • First set up a users table in your database where you store valid usernames and their passwords (as well as any other pertinent user information). Passwords should not be stored in plain text, but should generally be salted and hashed.
  • Add a login form to your application. When a user successfully logs in (which you can determine by taking the given password, salting and hashing it as above, and comparing it to the value in the database), use cookies or session to keep track of a login token.
  • On each page requiring authentication, the login token should be verified. If an invalid login token or no login token is given, redirect to the login form.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文