Jump to content

[SOLVED] Trouble with Sessions and file locations


_giles_

Recommended Posts

Hi all,

I’m working on my first project with sessions, kind of getting stuck on what is probably a simple point. Would you mind correcting me? My understanding is that I can declare the session variables in an include file such as

<?php
  if (!isset($_SESSION["count"]))
  {
    $_SESSION["start"] = time();
    $_SESSION["count"] = 1;
$_SESSION["counthistory"] = 1;
$_SESSION["lastpage"] = 100;
  }
  $_SESSION["count"]++;
?>

and that I can then access the session from other files such as :

<?php 
require_once "admin.inc";
session_start();
echo "session_id() is : " . session_id();
echo "</br>";
echo $_SESSION["count"];
?>

this is partly working, in that I can  return the session_id, but I get a “Undefined index: count” with the count parameter. what am I doing wrong?

I’d appreciate any help you could give me.
Thanks in advance
Giles
Link to comment
Share on other sites

thanks for the quick response ... works a treat!

guess the only thing leaving me a little puzzled is why do ALL the tutorials I've been working on put the include files at the top seemingly without getting into trouble? I thought I needed to put a reference to the file where I have the session variables before I try use them?
Link to comment
Share on other sites

You can also set session_start() on top inside your admin.inc file, then it would always be there but just written once.

When that is said, i would also recomend to rename the extention in admin.inc from .inc to .php since admin.inc probably contains config settings ? ? Just a safety issue (just ?!)
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.