加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php setcookie()函数用法及参数介绍

发布时间:2020-05-25 01:56:04 所属栏目:PHP 来源:互联网
导读:php setcookie()函数用于设置/创建一个HTTP cookie,本文章向大家介绍setcookie()函数用法以及该函数各个参数的作用,需要的朋友可以参考一下本文章。

setcookie函数参数介绍

setcookie语法:

setcookie(name,value,expire,path,domain,secure)

setcookie参数:

参数

描述

name

The name to set the cookie variable to and hence the name to access it with

value

The value of the current cookie

expire

When a cookie will expire (in the form of a Unix timestamp)

path

The directory where the cookie will be available for use

domain

The domain at which the cookie will be available

secure

Whether a cookie can be read on a non-SSL enable script

setcookie函数实例

$GLOBALS['username'] = "test";

$GLOBALS['password'] = "test";

/* http://www.manongjc.com/article/1251.html */

function validatelogin ($username,$password){

if (strcmp ($username,$GLOBALS['username']) == 0 && strcmp ($password,$GLOBALS['password']) == 0){

setcookie ("cookie_user",$username,time()+60*60*24*30);

setcookie ("cookie_pass",md5 ($password),time()+60*60*24*30);

return true;

} else {

return false;

}

}

if (validatelogin ("test","test")){

echo "Successfully logged in.";

} else {

echo "Sorry,invalid login.";

}

?>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读