setcookie函数的作用域问题

在不同目录下的文件.不能访问各自设置的cookie

查了一下手册.setcookie函数有一个path参数.可以设置本地cookie的作用域

解释如下:

The path on the server in which the cookie will be available on. If set to ‘/’, the cookie will be available within the entire domain . If set to ‘/foo/’, the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

另一个参数domain
则是设置网络上cookie的作用域.

解释如下:

The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you’d set it to ‘.example.com’. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details.

示例:

  1. $setcookday = 30;//设置cookie有效期
  2. setcookie('uname', '银子', time() + ($setcookday * 24 * 60 * 60),'/','qqdang.net'); //分别为cookie名称.cookie值.cookie有效时间.cookie本地作用域.cookie网络作用域

PHP导出Excel格式文件(xls)

PHP导出Excel格式文件(xls),比想像中要简单的多,只需给PHP文件加一个文件头,filename 就是导出的xls文件名,当你点击这个文件的URL时,就会提示你下载xls文件了

header("Content-Type: application/vnd.ms-execl");
header("Content-Disposition: attachment; filename=info.xls");
header("Pragma: no-cache");
header("Expires: 0");

以下是全部代码:

  1. <?php
  2. header("Content-Type: application/vnd.ms-execl");
  3. header("Content-Disposition: attachment; filename=info.xls");
  4. header("Pragma: no-cache");
  5. header("Expires: 0");
  6. require_once(dirname(__FILE__)."/../include/config_base.php");
  7. require_once(dirname(__FILE__)."/../dede/config.php");
  8. require_once(dirname(__FILE__)."/../include/pub_datalist.php");
  9. $dsql = new DedeSql(false);
  10.  
  11.  
  12. echo "订阅日期"."\t";
  13. echo "订阅内容"."\t";
  14. echo "姓名"."\t";
  15.  
  16.  
  17. $dsql->SetQuery("Select * from `TableName` order by `id` desc");
  18. $dsql->Execute();
  19. $i = 1;
  20.  
  21. while($row = $dsql->GetArray())
  22. {
  23.  
  24.  
  25.     echo $row['uTime']."\t";
  26.     echo $row['uCont']."\t";
  27.     echo $row['uName']."\t";
  28.    
  29.     $i++;
  30. }
  31. ?>

浏览最多的10篇日志

评论最多的10篇日志

随机显示的10篇日志