Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where exactly do I put a SESSION_START? [duplicate]

Tags:

php

session

login

So I'm starting my own website and I have the login file pretty much made. I just need to figure out where to put the session_start to keep the user logged in. Where exactly do I put the session_start? Do I put it right in the login file? Or where do I put it?

Thanks for the help

like image 806
user3053564 Avatar asked Dec 01 '13 03:12

user3053564


People also ask

Do I need to use session_start on every page?

php and put there all your repetitive code including session_start(); Show activity on this post. Anything that is going to access Session variables needs to start the session. So unless you have a php page that is non-dependent on the session than every page needs it.

When should the session_start () function be used?

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.

What is the use of session_start () and Session_destroy () functions in PHP?

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called. Note: You do not have to call session_destroy() from usual code.


1 Answers

Put it after your PHP start tag <?php ... like this

<?php
session_start();
//... your code....


//more code....

Read more on sessions from the PHP Manual. Here

Note : Also keep in mind, you need to call session_start(); on each and every page if you are making use of session variables.

like image 53
Shankar Narayana Damodaran Avatar answered Sep 19 '22 18:09

Shankar Narayana Damodaran