SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session in include

    is there anyway for placing a session in include that is in the middle of the page e.g

    PHP Code:
    include("1.php");
    include(
    "2.php");
    include(
    "3.php"); # This include contains session_start(); 
    The reason I want to do this is because, 3.php will be dynamically loaded into the page multiple times. After the first load, it doesn't recognize the session.

  2. #2
    SitePoint Zealot Gar onn's Avatar
    Join Date
    Feb 2011
    Location
    Belgium
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    <?php
      if (!isset ($_COOKIE[ini_get('session.name')])) {
        session_start();
      }
    ?>

    Will session start if not started yet. But I suggest that you session start on the top of the page witch includes the other files

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still getting this error:

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

  4. #4
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Start your session in the page that has the includes and the populate the session vars in include3.
    The session start needs to be the first thing outputted to your browser otherwise you will get the headers error.
    What I lack in acuracy I make up for in misteaks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •