67

I've searched around for use of localStorage in PHP, as I need to get localStorage data as a $var, in PHP and do stuff in PHP with it. Is this possible?

4

1 Answer 1

133

localStorage is something that is kept on the client side. There is no data transmitted to the server side.

You can only get the data with JavaScript and you can send it to the server side with Ajax.

Sign up to request clarification or add additional context in comments.

7 Comments

If php can access cookies, why the hell can't it access localStorage?
@B1KMusic: Because cookies are sent to the server in the request headers. It's not that PHP can access the client side. The browser sends the cookie data to the server.
I know this is correct, but could you update the answer to show how?
@FelixKling That explains the server READING cookie data, so how about WRITING it?
@ChuckLeButt: The sever can send Set-Cookie headers in the response. developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
|