您所在的位置:首页>>编程技术

js读取php生成的cookie

点击数:1420 更新时间:2014-04-06 15:20:00 来源: 厦门网站建设-返回
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
setcookie("username","js读取php生成的cookie,成功");
setcookie("password","密码");
echo $_COOKIE['username'];
?>
<script language="javascript">
function readCookie(name){
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++){
  var c = ca[i];
  while (c.charAt(0)=='') c=c.substring(1,c.length);
  //document.write(decodeURIComponent(c)+'<br>');
  if(c.indexOf(nameEQ)==0)returndecodeURIComponent(c.substring(nameEQ.length,c.length));
【责任编辑:CSW8923