Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get localStorage value into php [duplicate]

Tags:

javascript

php

I have a variable set in localStorage and I want to get it into php. When php is executed the value is already set in local storage, but how should I get into php?

I tried something like this:

  $myvar = "<script> localStorage.getItem('productinfo')['s3_url']</script>";

But this for some reasons gives a Uncaught SyntaxError: missing ) after argument list

How should I approach this? Thanks.

like image 531
funguy Avatar asked Oct 26 '25 03:10

funguy


1 Answers

You can not directly get a localStorage value in PHP, when script is executed, because localStorage is contained in user's browser, and PHP is running on server. However, you can send the value from localStorage to a server with GET or POST request.

like image 71
m0onspell Avatar answered Oct 27 '25 17:10

m0onspell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!