I am having a problem to get arguments from one HTML page to the other. The case is this:
I am using PHP and Ajax/jQuery to build this website and the first page is a login form.
When someone click in the button "login" I am sending a POST request with ajax to a PHP script that will search in the database for this user/password(I am using ajax because if an error occurs I will show a message without reload the page). When the PHP script finishes, it returns the user id to the login page.
How can I go from the login page to another page(e.g. Home) and keep the user id to use there. I know how to resolve this using location.href but I don't want to show the user Id in the URL.
Thank you.
问问题
125 次
3 回答
1
您应该依赖 PHP 中的会话变量来获取此类信息。您不能信任客户端发送给您的身份,否则他们可能会通过操纵客户端来欺骗自己的身份。
于 2013-05-02T00:54:23.233 回答
0
请注意,人们认为您可能对您的网站/用户 ID 进行的操作存在安全问题。但是,要解决您使用 javascript 提出的问题,您可以使用window.sessionStorage保存客户端的任何信息,直到窗口关闭。或者,如果您需要持久信息,那么您可以使用 window.localStorage。
于 2013-05-02T00:54:16.413 回答
0
尝试使用会话:
<?php
session_start(); //u have to have this on the top of your page, to be able to use session
$_SESSION["user_id"] = $user_id;
session_destroy(); //u can use this to unset the variables stored in the session. use only after u are done using with the $_SESSION.
?>
访问 $_SESSION 变量(就像 post 和 get):
$variable = $_SESSION["user_id"];
一旦你设置了会话,你就可以在你的任何页面中使用它们,就像一个全局变量一样,只要你把 session_start() 放在页面的开头
于 2013-05-02T00:59:35.070 回答