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

后端 未结 4 1395
无人及你
无人及你 2021-01-18 07:08

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?

4条回答
  •  醉话见心
    2021-01-18 07:48

    You want to pass a variable from HTML5 into PHP, which requires auto-submit. Try this, though I've never tried it myself.

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

     

    I didn't actually do the work for you, but I hope this gives you a good idea.

提交回复
热议问题