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
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?
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 ?!)

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.