Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if HTML5 sessionStorage value exists with PHP (like with cookies)

With PHP it's possible to check if a cookie exists. Is there a similar way to check if a HTML5 sessionStorage (webstorage) item exists?

like image 350
Mark de Vries Avatar asked Apr 29 '13 05:04

Mark de Vries


3 Answers

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

like image 117
Lasse Avatar answered Sep 27 '22 18:09

Lasse


No. PHP is server side language and storage or cache are browser dependent, so it is not possible check storage or cache directly from server.

like image 44
az pakistan Avatar answered Sep 27 '22 18:09

az pakistan


This 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'];
like image 35
afukada Avatar answered Sep 27 '22 17:09

afukada