Cookie across HTTP and HTTPS in PHP

后端 未结 2 961
春和景丽
春和景丽 2020-12-09 15:17

How can I set a cookie in PHP that is readable both in HTTP and HTTPS?

If this isn\'t possible, what can be done? Set two cookies?

2条回答
  •  旧时难觅i
    2020-12-09 15:33

    By default, a cookie can be read by both http and https at the same URL.

    However, a server can optionally specify the 'secure' flag while setting a cookie this tells the browser to only send it over a secure channel, such as an SSL connection.

    In this case the cookie will only be sent over https. A cookie not marked as secure will be sent over both http and https.

提交回复
热议问题