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.

Answers


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.


Note that there are security concerns with what people think you may be doing with your website/userId. However, to address what you have asked using javascript, you can use window.sessionStorage to save any information client side until the window is closed. Or if you need persistent information then you can use window.localStorage.


Need Your Help

Change timeout for table adapter (call stored procedure) in Visual Studio 2012 VB project?

sql vb.net visual-studio-2012 tableadapter

My problem: Call to a Stored Procedure is timing out after 30 seconds. Seems the auto-generated table adapter doesn't provide an interface to change it.

Using Non-Rest Calls with Loopback (Strongloop)

node.js rest express loopbackjs strongloop

We're using Loopback for our REST apis and would like to implement some standard Node Express-like calls through the same instance that do not get automatically routed through the Loopback framewor...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.