还记得跨页面的字段吗?

发布于 2024-10-31 23:25:39 字数 638 浏览 4 评论 0原文

我有这个: main.php:

ID: <input name="id" id="id" type="text" size="20" value="<?php echo $_POST['id']; ?>"><br>
Password: <input name="password" id="password" type="password" value="<?php echo $_POST['password']; ?>" size="20">

文件main.php是索引页。

文件 main.php 是一个带有 action="main.php" 的表单,

当我从 main.php 转到 console.php 时,我没有得到值 id 和密码。

当我从 main.php 转到plugins.php 时,我没有得到值 id 和密码。

从main.php,您可以进入plugins.php 和console.php。但那时你并没有得到这些值。

我知道为什么会这样。

如何解决这个问题?我怎样才能使当我转到console.php或plugins.php时,这些字段将被记住?

课程对我来说太难学了。还有其他解决办法吗?

I have this:
main.php:

ID: <input name="id" id="id" type="text" size="20" value="<?php echo $_POST['id']; ?>"><br>
Password: <input name="password" id="password" type="password" value="<?php echo $_POST['password']; ?>" size="20">

File main.php is index page.

File main.php is a form with action="main.php"

When i go from main.php to console.php, i dont get the values id and password.

When i go from main.php to plugins.php, i dont get the values id and password.

From main.php, you can get into plugins.php and console.php. But you don't get the values then.

I know why it happens.

How to fix this? How can i make, that when i go to console.php, or plugins.php, the fields will stay remembered?

Sessions are too hard for me to learn. Is there any other solution?

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

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

发布评论

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

评论(2

自找没趣 2024-11-07 23:25:39

太难了?简而言之,在您想要使用会话的每个页面的顶部,使用 session_start()。现在,您想将某些内容保存到会话中吗?

#page1
session_start();
$_SESSION['foo'] = 'bar';

#page2
session_start();
echo $_SESSION['foo'] #echoes bar

unset($_SESSION['foo']); #destroy foo
#if you want to discard the entire session, use
session_destroy(); #going down! 

所以,在你的情况下,也许是这样的:

#main.php
session_start();
if (isset($_POST['id'], $_POST['password'])) {
    $_SESSION['id'] = $_POST['id'];
    $_SESSION['password'] = $_POST['password'];
}
#rest of main.php

#console.php and plugins.php
session_start();
if (isset($_SESSION['id'], $_SESSION['password']))
    #do stuff

我觉得用勺子喂你很糟糕,但基本的会话功能确实是你所描述的情况所需要的,而且它可能是传递敏感信息的最简单的方法,这基本上就是会议的目的。

欲了解更多信息:

Too hard? Put simply, at the top of every page you want to use sessions with, use session_start(). Now, you want to save something to a session?

#page1
session_start();
$_SESSION['foo'] = 'bar';

#page2
session_start();
echo $_SESSION['foo'] #echoes bar

unset($_SESSION['foo']); #destroy foo
#if you want to discard the entire session, use
session_destroy(); #going down! 

So, in your case, maybe something like:

#main.php
session_start();
if (isset($_POST['id'], $_POST['password'])) {
    $_SESSION['id'] = $_POST['id'];
    $_SESSION['password'] = $_POST['password'];
}
#rest of main.php

#console.php and plugins.php
session_start();
if (isset($_SESSION['id'], $_SESSION['password']))
    #do stuff

I feel bad for spoon-feeding you with it, but basic session functionality is really all that's needed in the case you're describing, and it's probably the easiest way to pass around sensitive info, and is basically what sessions were made for.

For more info:

—━☆沉默づ 2024-11-07 23:25:39

1) 学习课程。切勿传递他人的密码。您应该对密码进行哈希处理,并根据数据库中的哈希值进行检查。检查匹配项后,您可以将用户经过身份验证的信息存储在会话变量中 - 您不再需要知道他们提交的密码。

2) 了解当您提交 html 表单时,表单的 action 是唯一可以直接使用发布的表单参数执行任何操作的页面。

...

尽量不要放弃学习这些东西 - 它们的创建是为了让你的生活更轻松,而不是更具挑战性。

供您使用的示例 PHP 身份验证类

1) Learn sessions. And never pass around someone's password. You should hash the password, and check it against a hashed value in your database. When you have checked for a match, you can store in your session variables that the user is authenticated - you no longer need to know which password they submitted.

2) Understand that when you submit an html form, the action of the form is the only page that can do anything directly with the posted form parameters.

...

Try not to give up on learning these things - they were created to make your life easier, not more challenging.

Example PHP authentication classes for you to use

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文