微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php 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函数实例

PHP

$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.";

}

?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐