在输出发送到浏览器后设置cookie [英] Set a cookie after output has been send to browser
本文介绍了在输出发送到浏览器后设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法,我可以在html输出后设置一个cookie?根据PHP手册,setcookie()应该在之前设置。
我需要它用于我的投票系统,一个成功的Mysql查询。
解决方案
您可以使用输出缓冲区,所以在脚本的顶部添加ob_start这将创建一个缓冲区,然后可以设置cookie,然后结束缓冲区并刷新到浏览器。
ob_start ();
/ * set cookie * /
ob_end_flush();
Is there a way that I can set a cookie after an html output? According to PHP manual setcookie() should be set before the output.
I need it for my voting system wherein a cookie will be set after a successful Mysql query. I made it in one file.
解决方案
you can use the output buffers so at the top of your script you add ob_start() and this will create a buffer and you can then set the cookie and then end the buffer and flush out to the browser.
ob_start();
/* set cookie */
ob_end_flush();
这篇关于在输出发送到浏览器后设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文