简体   繁体   English

如何重定向到其他页面并保存状态信息?

[英]How to redirect to a different page and save state information as well?

I am in a web scripting class and our teacher is very strict on the guidelines of the assignment, as he has scripts that grade our work. 我正在参加网络脚本课程,我们的老师对作业准则非常严格,因为他的脚本可以对我们的工作进行评分。 With that being said we are allowed to use only two forms for our assignment, one for logging in (form 1) and one for submitting data to be entered into a database (form 2). 话虽如此,我们只允许使用两种形式进行分配,一种用于登录(表单1),一种用于提交要输入数据库的数据(表单2)。

My instructions say: 我的说明说:

  • A user is required to submit their login credentials on form 1 用户需要在表格1上提交其登录凭据
  • If upon entering valid credentials the user is taken from form 1 to form 2 如果在输入有效凭证后将用户从表格1转到表格2

I've been saving state information for form 1 via hidden input types that will have form 1 either collect login credentials or check the login credentials. 我一直在通过隐藏的输入类型保存表单1的状态信息,这些输入将使表单1收集登录凭据或检查登录凭据。 I can do that great and I can also in fact check the login in credentials great too. 我可以做的很好,实际上我也可以检查凭据中的登录信息。 When the user is valid I can also redirect to form 2 via header(). 当用户有效时,我还可以通过header()重定向到表格2。 My problem is I need to save some sort of state information on what type of user was just validated (there can be an admin or regular user), and from what I understand at http://php.net/manual/en/function.header.php that the way I was saving my state information via hidden input types won't work as header() must be called before any actual output is sent. 我的问题是我需要保存某种状态信息,以了解刚刚验证过的用户类型(可以是管理员或普通用户),以及我在http://php.net/manual/zh/function上了解到的信息.header.php ,我通过隐藏的输入类型保存状态信息的方式将不作为header()起作用,必须在发送任何实际输出之前调用它。

Could someone please help point me in the right direction or inform me on how I can accomplish a redirect to form 2 while some how saving information on whether or not an admin or regular user was just validated? 有人可以帮我指出正确的方向,或者告诉我如何完成表格2的重定向,同时告诉我如何保存有关管理员或普通用户是否已通过验证的信息?

I was thinking of using my database to save the information but that doesn't seem very effective at all. 我当时在考虑使用数据库来保存信息,但这似乎并不十分有效。

Thanks for all the help. 感谢您的所有帮助。 :D :d

您应该研究使用session

session_start();
$_SESSION['some_value'] = $var

now you can access $_SESSION['some_value'] for that user, as long as you put session_start() at the top of the page. 现在,只要将session_start()放在页面顶部,您就可以访问该用户的$ _SESSION ['some_value']。

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

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