如何使用PHP制作Cookie [英] How to make a cookie with PHP

查看:77
本文介绍了如何使用PHP制作Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何为uuid设置cookie

您好,我想知道如何在PHP中制作Cookie。我已经研究了该主题几个小时,但是我对PHP还是一个新手,并且不太了解。我已经找到了这个脚本,但是不知道如何将其植入我的网站,有人可以帮忙吗?

Hello, I would like to know how to make a cookie in PHP. I have researched the topic for a couple of hours already, yet im a newbie to PHP and dont understand it that much. I have found this script, but dont know how to implant it into my website, can anyone help?

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


推荐答案

您想对Cookie做什么?如果要从请求到请求跟踪服务器上的信息,则可能要使用会话,它会自动使用cookie。

What do you want to do with your cookie? If you want to track information on the server from request-to-request, you probably want to use a session, which automatically uses cookies.

否则,请继续使用 setcookie 以获得应用程序需要其他功能的Cookie。请注意PHP手册中的以下代码段:

Otherwise, go ahead and use setcookie for cookies that your application needs for other functionality. Pay attention to this snippet from the PHP manual:


setcookie()将cookie定义为
以及其余的cookie HTTP
标头。像其他标头一样,必须在脚本
的任何输出之前发送cookie
(这是协议
的限制)。这要求您在
任何输出(包括和
标签以及任何空格)之前,先
对该函数进行调用。

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.







<?php setcookie("cookiename", uniqid()); ?> 

这篇关于如何使用PHP制作Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆