• 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 ?
0
Rozamunda
Asked:
Rozamunda
1 Solution
 
Greg AlexanderLead DeveloperCommented:
You need it at the top of the page that the class is on
0
 
RozamundaAuthor Commented:
so that means if i have a program:
<?
   session_start();

  require_once myclass.php
?>

i need to have also session_start
in myclass.php, if i refer there to a session ?. Yes ?
 
 
0
 
Greg AlexanderLead DeveloperCommented:
no, sessions are global, you will have access to the session even within the class
0
 
Neil_BradleyWeb UX/UI DeveloperCommented:
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}
0
 
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)
0
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