I’m reading up on here about cookies vs sessions. I see that the cookie is sent with every HTTP request, and I want to make sure i understand how the internets work.
Say like I have a page: test.php. Test.php has 10 script tags on it that go and pull JS scripts () and 5 tags that go pull images. Is loading Test.php 1 request or 16 requests?
I’m using a cookie to store last 10 visited urls and custom favorite urls. The favorite URLs can get pretty big. So I want to make sure that my 1KB of cookie data is sent only 1 time and not 16 times for each request.
Also, I’m using cookies because I already save my permission structure in SESSION, and that can get pretty big too…
Thanks.
Yes, it’s 16 requests.
I recommend you only use the
session_idcookie to identify your visitor (in PHP it’sPHPSESSIDI believe, it will get set automatically if you usesession_start()). Store the actual session data in a database or some data container of your own. This enables you to put as much in your a session as you want and prevents you from setting and sending too many cookies.See:
session_set_save_handler, it’s a very useful function.