I'm trying to make many of the pages in my site cache-able as HTML. As a result, I won't be able to call session_start() on those pages. Do sessions work if you don't call them on every single page?
4 Answers
If you don't call session_start()
than you won't have $_SESSION
available. But if the page is a static html file anyway than you won't need $_SESSION
for that page so you don't have to worry about it.
You only need it on pages where you do something with $_SESSION

- 78,177
- 11
- 137
- 148
No, they do not work. The session_start()
should be placed prior to any other program execution, even before the code that decides if the cached html is going to be presented or normal code execution should occur.

- 5,709
- 2
- 29
- 52
session_starts()
, either starts the session, or allows you to use the session variables. If you want to start a session and store values there or you want to use the session values already there then, you must use session_start()
Do sessions work if you don't call them on every single page?
NO

- 77,474
- 47
- 185
- 261
If you want to have most of your pages in html.Then it is better to mod-rewrite those pages from php to html.Then You can use session_start() at any page with html extension on it. check it.

- 21
- 2