Check if HTML5 sessionStorage value exists with PHP (e.g. using cookies)

With PHP, you can check if a cookie exists. Is there a similar way to check if an HTML5 element exists in sessionStorage (webstorage)?

+4
source share
4 answers

If you mean sessionStorage HTML5 web storage (as I understand from the tags in your question), then no. Access to this data with PHP is not possible. It can only be accessed using JavaScript and go to PHP using AJAX.

+3
source

It worked.

HTML side:

<body onLoad="submitform()"> <form name="myform" method="post" action="example.php"> <input type="text" name = "var" id="var"> </form> <script type="text/javascript"> function submitform() { document.getElementById("var").value = sessionStorage.getItem('var'); document.myform.submit(); } </script> 

PHP side:

 echo $_REQUEST['var']; 
+2
source

No. PHP is a server language, and the storage or cache is browser-dependent, so it is not possible to check the storage or cache directly from the server.

+1
source

You want to pass a variable from HTML5 to PHP, which requires automatic submission. Try it, although I have never tried it myself.

Create an invisible text input. Ask JavaScript to change the input value to the value returned from sessionStorage.getItem ("key") and use the string onload = 'this.form.submit () in the tag.

  <form name = 'phpvar' onload='this.form.submit()'><br> <input type = "text" value = sessionStorage.getItem("key")> 

I did not do this job for you, but I hope it gives you a good idea.

0
source

All Articles