Pass arguments from one HTML page to the other
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.
try to use sessions:
<?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. ?>
to access the $_SESSION variables(just like post and get):
$variable = $_SESSION["user_id"];
once u set the session u can use them in any of your page just like a global variable and as long as you put session_start() at the beginning of the page
You should rely on session variables in PHP for this kind of information. You cannot trust the identity that the client would send you, otherwise they could spoof their identity by manipulating the client-side.