Home > Article > Backend Development > PHP implementation reads Cookie set by JavaScript
This article mainly introduces how PHP reads Cookies set by JavaScript. Has very good reference value.
Cookies are used a lot in development, but what if you use JavaScript to set the cookie and then use PHP to read it out? That is, is it feasible to use cookies interactively under PHP and JavaScript?
<?php // 读取JavaScript设置的cookie header("Content-type: text/html; charset=utf-8"); if(isset($_COOKIE["param"])){ echo $_COOKIE["param"]; } ?> <script type="text/javascript"> function $_cookie(name,value){ var date = new Date(); $livetime = 5*24*3600*1000;// cookie生命周期 date.setTime(date.getTime()+$livetime); document.cookie = name+"="+value+";expires="+date.toGMTString(); } // 设置cookie $_cookie("param","javascript设置cookie"); </script>
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Detailed explanation of how to use session-cookie with php and codeigniter
# Detailed explanation of how to use Cookie in ##PHP
Comparative introduction of SESSION and COOKIE under PHP
The above is the detailed content of PHP implementation reads Cookie set by JavaScript. For more information, please follow other related articles on the PHP Chinese website!