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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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"); ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.