Jump to content

Holding session_start in an include file


brady123

Recommended Posts

I have an include file that is included in every page of my website. I'm using sessions and trying to streamline code.

 

The very first line of any page is my include file, and the very first thing in that file is:

 

<?php
session_start();
?>

 

The page doesn't register that a session was started. Do I have to have session_start() on every single page? Or is there a way to have it in my include file so it is automatically on every page for me?

 

Thank you!

Do I have to have session_start() on every single page? Or is there a way to have it in my include file so it is automatically on every page for me?

session_start() has to be ran on every page. How you do that is up to you. It can be on an included script or the script itself. Most people will put it in an file that is included at the start of every page.

I'm trying that, but it's not working. For example, I have this at the beginning, the very first thing, of every page:

 

<?php include ("/headerinfo.php"); ?>

 

The page continues from there. In that 'headerinfo' include file, I have on the very first line:

 

<?php session_start(); ?>

 

I imagine that's what I need to do to have sessions started on every page, but for some reason, pages aren't recognizing it.

 

Any thoughts/tips?

Are you sure the include() is actually working? Check you error logs for errors regarding the include function, and try echoing something directly from the included file. My guess is that the path is probably wrong.

I'm trying that, but it's not working. For example, I have this at the beginning, the very first thing, of every page:

 

<?php include ("/headerinfo.php"); ?>

 

The page continues from there. In that 'headerinfo' include file, I have on the very first line:

 

<?php session_start(); ?>

 

I imagine that's what I need to do to have sessions started on every page, but for some reason, pages aren't recognizing it.

 

Any thoughts/tips?

 

 

dont use <?php include ("/headerinfo.php"); ?>  it should be <?php include ("headerinfo.php"); ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.