Prevent Cookies From Being Sent on AJAX Request

前端 未结 5 1158
庸人自扰
庸人自扰 2021-02-05 00:58

I have a web service that I invoke from script but that does not need any information stored in cookies. Anytime I make a request to the service, the cookie is sent along with i

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 01:25

    You are correct in saying that browsers send matching (path + domain + session) cookies along with the HTTP request. This is critical for the cookie mechanism to work.

    Couldn't you simply, not read the cookies?

    Additionally, when the cookie is originally set, you can set what directory (and its subdirectories) can access the cookie.

    For example, if you set a cookie to be read in /foo/bar/ only, a file located in /whatever/ajaxHandler.php cannot see those those cookies.

    Check this out: http://us.php.net/setcookie

    While I'm not sure if you're using PHP, it could be a good starting point for you.

提交回复
热议问题