PHP cookies问题,在Firefox不工作在其他浏览器 [英] PHP cookies problem, works in Firefox not in other browser

查看:127
本文介绍了PHP cookies问题,在Firefox不工作在其他浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中设置Cookie时遇到问题。我不得不说我对php不是很有经验,所以也许是一个非常愚蠢的问题。



我有一个ajax评级系统,应该检查一个cookie



使用ajax调用的网页检查Cookie,添加您投票的照片的ID,并将其调用函数:

  setcookie(Name,$ cookie,time()+(60 * 24 * 365) ,$ _SERVER ['HTTP_HOST'],0); 

显示照片的页面也会调用cookie

  $ cookie = $ _COOKIE ['Name']; 

并检查您是否已投票。



问题可能是ajax页面位于与显示照片的页面不同的目录中。



显示照片的页面位于根目录,投票的页面在/ajax/vote.php



投票系统工作,在我检查IP之前,但知道我需要检查cookie。



它在Firefox中工作没有任何问题,但是当我开始在IE和Safari上测试时,似乎他们没有看到cookie。 p>

我已经检查过IECookieViewer,当我投票的时候,cookie是创建的,但是当我回到页面,它看起来像页面没有找到曲奇饼。



对不起的英语,我希望问题是可以理解的



PS忘记指出可能与问题相关的东西。页面位于iframe中。

解决方案

检查其他浏览器的Cookie设置,并在退出时将其设置为全部阻止或清空。



如果Cookie在一个浏览器中工作,而不是另一个浏览器,则需要确保其他浏览器首先设置Cookie。



有时它会看起来像你可以创建的cookie,但它会消失或删除每一个页面重新加载。



来自iframe的Cookie



这也可能是因为您在iframe中设置Cookie,浏览器可能会将其视为第三方Cookie并拒绝它,除非在浏览器首选项中明确指定允许第三方Cookie



在这种情况下,您需要一个紧凑的隐私政策(或

p>对于PHP,您可以将其添加为设置cookie的页面的头部:

  IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'); 


I've a problem with setting cookies in php. I've to say that I'm not very experienced with php, so maybe is a very stupid problem.

I've an ajax rating system that should check a cookie to see if the the photo has already been voted.

The page called with ajax check for the cookie, add the id of the photo you are voting to it and call this function:

   setcookie("Name", $cookie, time()+(60*24*365), "/",  $_SERVER['HTTP_HOST'], 0); 

The page that display the photo also call the cookie

   $cookie = $_COOKIE['Name'];

and check to see if you have already voted.

A problem may be the fact that the ajax page is in a different directory than the page that display the photo.

The page that display the photo is in the root directory, the page that cast the vote is in /ajax/vote.php

The voting system works, before I was checking the IPs, but know i need to check the cookies.

It work in Firefox without any problem, but when I've started testing on IE and Safari it seem they don't see the cookie.

I've checked with IECookieViewer and when I cast a vote the cookie is created allright, but when I go back to the page, it look like the page don't find the cookie. Also if I cast another vote the cookie is replaced with a new one.

Sorry for the bad english, I hope the problem is understandable

P.S. Forgot to point something that might be related to the problem. The page is inside an iframe.

解决方案

Check the cookie settings of the other browsers and if they're set to block all or empty on exit.

If the cookies work in one browser, but not another, you will need to make sure that the other browser is letting you set cookies in the first place.

Sometimes it will look like you can create the cookie, but then it will disappear or be deleted with each page reload.

Cookies from an iframe

It's also possible that because you're setting the cookies in an iframe, that the browsers may view it as a third-party cookie and reject it unless explicitly set out in the browser preferences to allow third-party cookies.

In that case you would need a compact privacy policy (or a compact P3P header) on the pages from where you're trying to set the cookies from.

For PHP, you would add this as your header for the page setting the cookie:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); 

这篇关于PHP cookies问题,在Firefox不工作在其他浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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