Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get data from localstorage using php

Can I get data from localstorage using php if yes then tell me how in localstorage data set like this

<script>
var i=0;
function inc()
{
    i+=1;
    localStorage.setItem("qnum", i);
}
</script>
like image 227
prashant kushwah Avatar asked Mar 13 '26 06:03

prashant kushwah


2 Answers

No, you can't. PHP runs on your server, the localStorage is only available in the browser of the client.

The only way is to read the localStorage via JavaScript, and send the result to your server via ajax.

like image 135
Markus Kollers Avatar answered Mar 15 '26 20:03

Markus Kollers


I tried with this code and it worked fine.

$Data = "<script>document.write(localStorage.getItem('key'));</script>";
print_r($Data);
like image 38
Rohit Avatar answered Mar 15 '26 18:03

Rohit



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!