i am having trouble using session variables... this code was working for a long time (6 mths) without hassles and then suddenly ... i have a problem of

"undefined index" when i try to access the session variables on a different page than where i d set them

this is the index page of the control panel where the session vars are set

<?php
session_start();
$HTTP_SESSION_VARS['admin'] = FALSE;
//$_SESSION['admin'] = FALSE;
$admin = false;
include 'backend.php';
if(!isset($_POST['uname']))
{
?>
some html
<?php
} 
elseif($_POST['uname']=='admin' && $_POST['pword']=='rr543')
{
$_SESSION['admin']= TRUE;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
  <head>
   <meta name="generator" content="PSPad editor, www.pspad.com" />
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />

  <title>Welcome To &quot;xxxxxxxxxx&quot;</title>
   <link href="../styleshop.css" rel="stylesheet" type="text/css" />

  <script src="comjs.js" type="text/javascript"></script>
 </head>
 <body>
 <br /><br /><br /><br /><br /><br />
 <table class = "log" cellpadding = "0" cellspacing ="0">
 <th colspan ="100%">Select Operation</th>
 <tr><td><a href = "addprod.php">Add Product</a></td><td><a href ="vieword.php">View Orders</a></td><td><a href ="edit.php">Edit Product</a></td></tr>
 </table>
 </body>
 </html>
<?php
}
else
{
?>
some html
 <?php
 }
 ?>

then this is the code for the view orders page where the $SESSION['admin'] is called ... this is where the error occurs "undefined index" i feel the session is not being registered...this is just one of many errors on the site ... an entire shopping cart is dysfunctional due to this error...

<?php
session_start();
include 'backend.php';
error_reporting(E_ALL);
$isadmin=$_SESSION['admin'];
//var_dump($_SESSION);

if(!$isadmin)
{
//echo $isadmin;
die("Unauthorised Access");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
  <head>
   <meta name="generator" content="PSPad editor, www.pspad.com" />
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />

  <title>Welcome To &quot;xxxxxxxxx&quot;</title>
   <link href="../styleshop.css" rel="stylesheet" type="text/css" />

  <script src="comjs.js" type="text/javascript"></script>
 </head>
 <body>
 <?php
 vieword();
 ?>
 </body>
 </html> 

the file backend.php contains only functions ... no output is generated in this file..
this site is hosted on a webhost running php as cgi (fastcgi)... the version is 4.4.0

i know i have not used isset ... i would be totally embarassed if that is causing the prob... btw this very code works on my server...

please help

    Include
    session_write_close() after you've put all the values into $_session

      Alternatively, if that doesn't work, output [man]session_id/man on each page. If the ID changes, then the SID isn't being propogated properly. Normally, this is because the session.use_cookies directive is disabled; enabling it will probably resolve the issue.

      If not, you'll have to manually propogate the SID via the URL (which can lead to security problems).

        I checked the session ids and they are different on diff pages...
        and
        session_use_cookies = 1

        any one know what is causing this ... is it that new sessions are created with every session_start();

        thx in advance

          First, doublecheck your php info file on your localhost, as well as the server you're hosting the site on, to see what's enabled/disabled, using a small script like so:

          <?php
          phpinfo();
          ?>

          You also might make sure that session.cookie_secure is set to 'Off' if you are NOT going through https. Everytime you navigate the site your session data will not be retrieved and your sessionid will change.

          Also, what browsers are you testing this on? IE has some security settings that can cause problems.

            Can you give us a link to these pages? That way, we can check the cookie information (domain, path, etc.).

              9 days later

              the url is
              http://www.roopkalasarees.com

              you can check the shopping caRT under online store ... the items never get added to the cart.. as it relies on session variables... thinking of using a temp table but how feasible is that... any views

              and i have been testing this on all majr browsers except safari

              still havent been able to resolve this i think i ll shift to manual propagation and then redesign the site...

              thx and srry for the delay .

                I see that you are attempting to propogate the SID via the URL. If this isn't working for you (at the time, I'm getting a bunch of "Undefined index.." errors and I don't think the shopping bag feature is working), try changing the "session.name" to be the same as the variable name you're using in the URL (e.g. sessid). Otherwise, pass the SID using "?PHPSESSID=sid_here".

                  Write a Reply...