_giles_ Posted December 14, 2006 Share Posted December 14, 2006 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 advanceGiles Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 the session_start() must be above where ever you are using any $_SESSION variable. If you are using sessions, it is generally safe to ALWAYS MAKE SESSION_START() THE FIRST THING IN YOUR SCRIPT. Quote Link to comment Share on other sites More sharing options...
_giles_ Posted December 14, 2006 Author Share Posted December 14, 2006 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? Quote Link to comment Share on other sites More sharing options...
alpine Posted December 15, 2006 Share Posted December 15, 2006 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 ?!) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.