drxm5014 2018-09-27 11:04
浏览 192
已采纳

无法从ASP Msxml2.ServerXMLHTTP.6.0对象调用的PHP中设置cookie

I'm calling a php script from an asp page. The problem is that the php script called in this way cannot set the cookie. Here are the 2 scripts:

setcookie.asp

<%
    Dim objXMLHTTP
    Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
    objXMLHTTP.Open "POST", "http://127.0.0.1/setcookie.php", False
    objXMLHTTP.Send
    if len(objXMLHTTP.responseText)>0 then response.write "Result: "&objXMLHTTP.responseText
    Set objXMLHTTP = Nothing
%>

setcookie.php

<?php
setcookie('mycookie', '12345', time() + (86400 * 30), "/");
echo 'ok';
?>

The two pages run under the same website, in the same folder. I tried with both "POST" and "GET" with no success. If I run the php directly, cookie is created.

Any advice? Thanks

  • 写回答

1条回答 默认 最新

  • duanshan3331 2018-09-27 16:31
    关注

    You're using server side code to call your php script. This means that the cookie will be created on the server, not on the user's machine. Even if you're using a development server on your own machine your browser probably won't know where to look for the cookie if it hasn't set it. You need to use client side code to to call your php page, you could look for a Javascript/Ajax solution or you could use a zero size iframe.

    Alternatively you could learn how to use Classic ASP to set cookies.

    Using Cookies in ASP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)