Link to home
Start Free TrialLog in
Avatar of Rozamunda
Rozamunda

asked on

session_start in PHP class file

Do I  need session_start in the beginning of a class file in PHP to use $_SESSION ?
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

You need it at the top of the page that the class is on
Avatar of Rozamunda
Rozamunda

ASKER

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 ?
 
 
ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}
Avatar of Loganathan Natarajan
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)