今天做一个网站使用多个联盟营销的解决方案。需要用到cookie,于是我就写了一个如下类的php程序 ?php $_COOKIE['userName']='XXX'; print_r($_COOKIE);? 打印出来的cookie没有问题,把程序的第一行改成$_COOKIE['Name']=AAA再次运行后。会发现userName已经不
今天做一个网站使用多个联盟营销的解决方案。需要用到cookie,于是我就写了一个如下类似的php程序
<?php $_COOKIE['userName']='XXX'; print_r($_COOKIE); ?>
打印出来的cookie值没有问题,把程序的第一行改成$_COOKIE['Name']="AAA"再次运行后。会发现userName已经不在cookie中了。这是因为没有给cookie设置过期时间,而其默认的作用时间是一次会话(或浏览器关闭)。
设置cookie过期的php函数:bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )第一个参数就是放入的名称,第二个是放入cookie中的值。第三个就是设置cookie的过期时间,单位是秒。例我想把 userName='123'放到cookie,在20天之内从cookie中都能取到该值。
setcookie("userName","123",time()+60*60*24*20);
如果我在setcookie下面加 print_r($_COOKIE)是没法看到刚刚放到cookie中字段的值。这个函数设置的cookie值不会在本页生效。可以在到期前通过其它页面进行访问,或者刷新本页面。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!
