• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

session_start in PHP class file

Do I  need session_start in the beginning of a class file in PHP to use $_SESSION ?
1 Solution
Greg AlexanderLead DeveloperCommented:
You need it at the top of the page that the class is on
RozamundaAuthor Commented:
so that means if i have a program:

  require_once myclass.php

i need to have also session_start
in myclass.php, if i refer there to a session ?. Yes ?
Greg AlexanderLead DeveloperCommented:
no, sessions are global, you will have access to the session even within the class
Neil_BradleyWeb UX/UI DeveloperCommented:
//initialize the session
if (!isset($_SESSION)) {
Loganathan NatarajanLAMP DeveloperCommented:
You need not start the session on every page, it can be included once in any include file .. so that it would be referred all the pages.. (included)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now