Implement session function in PHP3 (two, cookie function library: COOKIE.INC.PHP3) (translate)

Source: Internet
Author: User
Tags html header implement min
cookie|session| function <?php
if (!isset ($__cookie_inc__)) {
$__cookie_inc__=1;
function Jssetcookie ($CName, $CValue, $CExpr =false) {
This function allows you to set cookies after the HTML header tag,
Can be supplemented with setcookie functions, or even replaced.
$CName ...: The name of a cookie
$CValue ...: The value of a cookie
$CEXPR ...: The validity period of the cookie, in minutes, can also modify the join hours, days

if ($CExpr > 0) {
$CookieString = "astr= ' $CName ' + ' = ' + ' $CValue ' + '; expires= ' + expr + ';p ath=/';";
$Cookie. = "\n<script language=\" javascript\ ">\n";
$Cookie. = ' function makeyearexpdate (min) {
var expire = new Date ();
Expire.settime (Expire.gettime () + (min * 60) * 1000));
expire = expire.togmtstring ()
return expire
}
Expr =makeyearexpdate ('. $CExpr. ');
$Cookie. = "\ n". $CookieString. " \ n ";
$Cookie. = "document.cookie=astr;\n</script>\n";
}else{
$Cookie. = "\n<script language=\" javascript\ ">\n";
$Cookie. = "Document.cookie= ' $CName = $CValue;p ath=/';";
$Cookie. = "\n</script>\n";
}
Echo $Cookie;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.