Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use HTML5 local storage along side PHP, use that for php sessions, and store other information that php uses

I have been looking on the web for some time now and HTML5 local storage seems to look like something useful to me and a solution to my problem that I am having with PHP sessions, the problem is that they are not consistent even if I set them to remember me the next time I come to my home page I am taken to the login page, this is not always, but often, PHP sessions are proving inconsistent for me.

I would like to know if i can use local storage for consistent session storage that php can use, all the examples i have seen on the web use javascript.

like image 338
Abdullah Khan Avatar asked Jul 24 '10 12:07

Abdullah Khan


2 Answers

Localstorage is for saving data client side so that it can be accessed even if the client is offline, in which case it is accessed, as you said, using JavaScript.

PHP sessions store information on the server. Using localStorage is also a bad idea because it can be modified by the client, so the client could claim to be logged in as a different user which is obviously a security issue.

Is there a problem with your PHP configuration? Is there a timeout value for the PHP session cookie that you can change?

like image 127
tjvr Avatar answered Oct 13 '22 10:10

tjvr


No. PHP runs on the server and has no access to the local storage API of the browser.

like image 20
Quentin Avatar answered Oct 13 '22 10:10

Quentin