Are you sick of having to type this code:
On every page which requires user authentication and other aspects which require the use of session variables? Welcome to the club. In this article I’m going to show you some of the ways on how to ditch the freakin’ code.
Here’s what a php header file might look like:
Its not necessary to put <?php ?> tags on a header file. As you can see in the code above. But if you will need to perform operations which require the power of the server side. Then you should enclose them in <?php ?> tags.
Then you can just import them later, in a different file:
You can also edit the php.ini file and automatically start a session of every page.
Just search for this line:
And change it to this:
Restart php, or better yet all the services associated with it (Apache, mysql). Then create a new session without doing the session_start() code.
Make another file and paste this code:
See if it outputs the session that you created earlier. It should look like this: