Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

i start a programming of simple cms

i created a index , contact , faq , ... page that all of these pages use from 2 files header.php and footer.php

now i have a problem with some code like usage session

if i use session_start() function in header , this code repeat in all page that use from header.php ... and this action maybe do conflict over than other page

what is a best solution for use code (like session or cookie) in a shared page (like header.php) ?

please help me

thanks a lot
Posted

1 solution

You can call session_start as many times you like, if a session is already opened it won't change it in any form. Still, I suggest to put it in an utility file, that you include before including anything else, and first of all, before writing anything in the response body (except if you use output buffering). I am usually creating a config.php file, that contains all necessary configuration settings and initialization procedures, including starting session.
A note: in case of cookieless session you might need to have other considerations too.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900