PHP implementation reads Cookie set by JavaScript

墨辰丷
Release: 2023-03-27 19:58:01
Original
1137 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!