duanfu7004 2016-03-05 14:45
浏览 75

Ajax:CROSS-DOMAIN请求不使用PHP设置Safari IOS的​​cookie

I'm trying to set a cookie using PHP CROS-DOMAIN, meaning my JS is hosted in other domain, the JS call to PHP page which trying to set a cookie. It works in all browsers except to Safari in mobile (iPhone 6) The weird thing is that I can get to user cookies but not to set (sometimes it sets an empty cookie, with 0 bytes)

here is my code in the php file:

header('Access-Control-Allow-Origin: '.$origin);        
header('Access-Control-Allow-Methods: POST, OPTIONS, GET, PUT');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: X-Requested-With');
header('Access-Control-Max-Age: 1728000');
setcookie("display_session_id", "1234", time() + (60 * 43800), "/", '.mydomain.com', false);

I tried to put * instead the $origin but it wasn't work. Also I tried to put those declarations in my .htaccess but it wasn't work. Server: Apache PHP version: 5.4.45

here are the headers from Safari

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-11-29 13:23
    关注

    Safari now blocks almost all cross-domain cookies from unknown domains by default. What this means is this:

    Main Site: example.com
    Cookie Site: cookie.com
    

    If the user goes to example.com and they've never been to cookie.com, Safari will not allow them to store a cookie for cookie.com. If the user goes to example.com and has previously been to cookie.com, Safari will allow the cookie no questions asked.

    This is the default policy, however you should also be having issues with Safari on the desktop and Internet Explorer's new policy that messes with P3P.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看