Why when set php cookie path to “/” doesn”t work for every subdirs in the domain, but just for the current directory.

Đang xem: Php setcookie tips: find out how to set up php cookies

cookie is set like:

setcookie(“name”, “val”, expire_time, “/”);It just doesn”t want to work.

try including the domain parameter:

setcookie(“name”, “val”, expire_time, “/”, “.domain.com”);// don”t forget the prefixing period: .domain.comthat will enable all sudomains of “domain.com”

*

*

Setting the cookie path to / should make it available to the entire domain. If you set your cookie like that, and it isn”t being sent, there is something else wrong.

Try using the Web Developer addon in Firefox. It shows you details on the available cookies. Maybe that can help you diagnose the problem.

Xem thêm:

*

Late to the party, I know. But I just discovered that my issue was pretty stupid, but I”ll post it for completion:

I was neglecting to add time() to the expires time on the cookie, so it was expiring immediately.

The expires time should be time() + seconds

*

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Xem thêm: Mang Thai Hay Bị Nhói Bụng, Lưu Ý Khi Đau Bụng Ở Giai Đoạn Đầu Mới Mang Thai

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

*

New Introducing Filters for Stack Overflow

Filters aren’t just for selfies anymore. Introducing Filters for Stack Overflow – the best way to beautify the site where you spend 10 hours a day.

Default theme

*

Bookface theme

*

Hot dog stand theme

*

Frisa Lank theme

*

MariOverflow theme

*

Terminal theme

*

Top Secret theme

*

Windows 3.1 theme

*

3D glasses theme
Default by Stack Overflow Bookface by Tom Hot dog stand by The Delicious One Frisa Lank by Child of the ’90s MariOverflow by Luigi Luigi Terminal by Neo Top Secret by Agents J & K Windows 3.1 by Ms. Dos 3D glasses by Digital Dimension Designers
Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2022.4.1.41852

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *