1

I'm going nuts to try to understand why the script below (let's call it script1 is passing session variable $_SESSION['emptystcode'] to bulkstOLD.php but not the other two: $_SESSION['dlstrest'] and $_SESSION['dllist']. I have session_start(); on the first command line of the called script.

All this script1 does is to $_GET the Restaurant and List names and display a form where the user can fill in a CODE field and submit it.

To makes things worse, I've created another script (a simplified version of this caller script) which just set the session variables and calls the same bulkstOLD.php and it works ok. I wonder if this has something to do with the $_GET. Any help would be much appreciated.. Thanks!!

Here is the code:

<?php
session_start();
include ('logged.php'); 
require_once ('functions.php');
$acisversion = $_SESSION['acisversion']; 
reset_all();
$cyear = date(Y);
$cmonth = date(M);
$cday = date(d);
$configs = include('config.php');
$_SESSION["module"] = 'st';
$_SESSION['favstlists_ref'] = 0;
$strest = $dlstrest = $_GET['dlstrest'];
$favstlist = $dllist = $_GET['dllist'];
$restname = 'restname_'.$strest;
$stlistrest = $configs[$restname]; 
?>


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>ACIS - Edit Lists</title>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script> 
<script type="text/javascript" src="stmenu.js"></script>
<style type="text/css">
@import url(acis.css);
</style>

<script type="text/javascript" src="js.js"></script>

</head>
<body>

    <div id="content">
<?php

  $_SESSION['stcodesub'] = $stcodesub = $stcode = ($_POST["stcodein"]);

  dbfile_init() ; 
   $_SESSION['stcode'] = $stcode;

if(isset($_POST["editSave"]))
      { 

            connect_db ();
            if (!empty($stcode))
            {                  
               check_code_for_st_list();

                $emptystcode = 0;
            }
            else
            { 
                $emptystcode = 1;                
            }

            $_SESSION['dlstrest'] = $dlstrest;
            $_SESSION['dllist'] = $dllist;
            $_SESSION['emptystcode'] =  $emptystcode;  

            if ((!$emptystcode and $codestok) or $emptystcode)
                { 
                    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=bulkstOLD.php">';
                    exit;  
                }
     }

?>
<table width="100%" border="0" align="center">
  <tr>
     <td width="223" align="left"></td>
     <td width="111" align="right"></td>
  </tr>
</table>


</style>
<form method="post" id="editLists" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<table width="739" border="0" align="center" cellspacing="0" bgcolor="#171717">
     <tr>
    <td colspan="3" 
    style="color:#00CC00;
    text-align: left;
    padding: 0;
    background: #2e2e2e url(images/nav_bar.jpg) repeat-x;
    font-size: 0.9em;
    color: white;
    height:16px;"><script type="text/javascript" src="mainmenu.js"></script></td>
    </tr>
  <tr>
    <td width="502"><h2 style="color:red;"> Atualizar Listas Favoritas de Pratos</h2></style></td>
    <td width="231" colspan="2" align="right"><?php echo $configs[footer];?></td>
    </tr>
  <tr>
    <td colspan="3" align="right"  ><table width="100%" border="0" align="center">
      <tr>
        <td align="center">Restaurante:</td>
        <td width="84" align="center" valign="bottom">Adicionar Código</td>
        <td width="350" align="center">Lista a ser atualizada:</td>
        <td width="150" align="left" valign="bottom"><span class="error"><?php echo $favErr;?></span></td>
        </tr>
      <tr>

        <td width="135" align="center"><b><?php echo $stlistrest; ?></b></td>
        <td align="center">
<?php
         echo $stcodeline;
?>
        </td>
        <td align="center"><b><?php echo $dllist; ?></b></td>
        <td align="right"><input type="submit" name="editSave" style="background-color: #009900; color: #FFFFFF;" value="Submeter" /></td>
        </tr>
      </table></td>
  </tr>

</table>
</form>



<?php


$_SESSION["module"] = 'st';

?>

</div>


</body>
</html>
7
  • 1
    session_start(); must be inside all files using sessions. Is it? If not, do. Commented Jan 21, 2015 at 15:38
  • I have them as the first command on each script Commented Jan 21, 2015 at 15:42
  • 1
    The first occurence of $dlstrest; is in $_SESSION['dlstrest'] = $dlstrest;. Where does $dlstrest come from? Since you mentioned $_GET: Just in case you rely on GET parameters like ....?dlstrest=xyz&.... to be imported as global variables - that's by default not the case since 2002 and you'd have to check the existence of that parameter(s) anyway. Commented Jan 21, 2015 at 15:45
  • If those session values aren't being set then, well, those session values aren't being set. What's different between this script and the simplified one which "works"? When you debug this, where does it fail? Commented Jan 21, 2015 at 15:47
  • I second VolkerK's comment. $dlstrest and $dllist only occur in your code when you're setting the session variables. Are they initialized elsewhere? If not, that's your problem Commented Jan 21, 2015 at 15:47

2 Answers 2

2

The only possible explanation for your problem is that you might have not written <?php session_start();?> in the very beginning, before any HTML tags(even doctype). Write it on top of every relevant php document.

Sign up to request clarification or add additional context in comments.

3 Comments

I did.... the called script is able to recover ONE of the session variables but not the other two
Yes.. that's why I'm puzzled... I reckon is something to do with the $_GET and the form submission... just guessing..
years later and this was the actually worked with my situation lol - thank you!! huge shoutout to you
-1

Look if all your files are saved as UTF-8 without BOM, not just UTF-8. This BOM dissables sessions.

And look if all your files are called as they are in the same subdomain.

www.domain.com/file1.php,
ww2.domain.com/file2.php,
domain.com/file3.php

... with diferent subdomains should not work.

1 Comment

I/m running the scripts via WEBMATRIX + LOCALHOST ... The session variables work ok in all other scripts.... Somehow, in this one it gets the variables via $_GET but the value somehow gets erase when I submit it (execute the bulkstOLD.php). Maybe this has nothing to do with SESSION but rather something happening to the variables obtained via $_GET as these two are the ones disappearing...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.