Jump to content

SESSION variables


ICubis2

Recommended Posts

Hi.  I'm brand new to this forum, so sorry if I do something wrong...

 

I'm someone who has thought myself to code in php to add dynamic objects to my basic static websites.  I have had no formal education.  This is not my first project however. 

 

I'm having problems with session variables working fine up to a point when I call a new file and then all my session variables are lost.  I have tried everything, but cannot keep them alive when I get into this or any other new file.

 

I display a form, get user data submitted, then display a next form and after the user submits this next form all the session variables are lost.

 

Anyone have any idea what is killing my session variables?

 

Thanks in advance.

Link to comment
Share on other sites

<?php
session_start();
echo "Num_Part = ".$_SESSION['Num_Part']."<br />"; 

echo "Num_Teams = ".$_SESSION['Num_Teams']."<br />"; 

echo "Ref_Numbers = ".$_SESSION['Ref_Numbers']."<br />"; 

echo "Format = ".$_SESSION['Format']."<br />"; 

echo "High_low = ".$_SESSION['High_low']."<br />"; 

echo "High_low = ".$_SESSION['High_low']."<br />"; 

echo "Unit = ".$_SESSION['Unit']."<br />"; 

?>

Link to comment
Share on other sites

More background info...

 

I use Yahoo! Small Business webhosting and am operating within their system.  I have never had to worry about understanding any of the backend stuff php app stuff.  I just create static HTML pages with their Sitebuilder and then modify and create new php files with their file manager.  (I also use their MySQL apps to manage and create databases, but at this point this project has no database.)  Sorry, I don't know much more about this than that.

 

The file code I provided is the file where the session variables are lost.  The session variables are of course defined in other files before this.  They even work fine in files before this.  The file that calls this code file is mainly an HTML file that presents a form.  This file code is called when a SUBMIT button is selected and the variables are lost entering this file.

 

Do you need to see the code in the calling file?

 

Sorry, I'm such a newbie and don't know how to communicate properly.

Link to comment
Share on other sites

<?php
session_start();
?>
<!--$sitebuilder version="2.6" extra="Java(1.6.0_05)" md5="1103a396ae2cf073a0d7c1ee03d35b27"$-->
<!--$templateKey HotJobs|Nexus - Olive|2.0$-->
<html>
  <head>
    <title>Kind-Comp Tool</title>
    <meta name="generator" content="Yahoo! SiteBuilder/2.6/1.6.0_05">
    <meta name="author" content="P. Joseph Shumaker Jr.">
    <meta name="keywords" content="Sports competitions, Individual sports, training competition, practice competition, Shuamker Competition, Kind Compeition,">
    <!--$page margin 0, 1, 20, 1$-->
    <!--$fontFamily Arial$-->
    <!--$fontSize 12$-->
    <style type="text/css"><!--
      BODY {font-family:"Arial"; font-size:12;margin:0px;padding:0px;}
      P {font-family:"Arial"; font-size:12;}
      FORM {margin:0;padding:0;}
    --></style>
    <script type="text/javascript">// workaround for IE table layout bugs
      function tableWorkaround(cols) { if (document.all) { document.write('<tr>'); for (var i = 0; i < cols; i++) { document.write('<td></td>'); } document.write('</tr>') }; }
      function tableWorkaround2_colheader() { if (document.all) { document.write('<col width="0">') }; }
      function tableWorkaround2(rowHeight) { if (document.all) { document.write('<td height="' + rowHeight + '">'); document.write('</td>') }; }
    </script>
  </head>
  <body bgcolor="#FFFFFF" background="clipart/backgrounds/sidebar/oliveBars_grayLines.gif" text="#666666" link="#0000FF" vlink="#800080" topmargin="0" leftmargin="0">

<!--$begin exclude$-->
    <div id="root" style="position:absolute;width:760px;height:1449px;">
<!--$end exclude$-->
      <div id="e0" style="position:absolute;left:588;top:0;width:171;height:139;">
        <table border="0" cellspacing="0" cellpadding="0" width="171">
          <tr>
            <td nowrap height="139" valign="top" bgcolor="#FFFFFF"><!--$emptyText$--></td>
          </tr>
        </table>
      </div>
      <div id="e1" style="position:absolute;left:171;top:105;width:575;height:32;">
        <table border="0" cellspacing="0" cellpadding="0" width="575">
          <tr>
            <td nowrap height="32" valign="top" bgcolor="#C3C89B"><!--$emptyText$--></td>
          </tr>
        </table>
      </div>
      <div id="e2" style="position:absolute;left:168;top:2;width:576;height:101;"><!--$img %RemappedImageAsset:/sitebuilder/clipart/bars/regular/horizontal/AbstractOlive.jpg$--><img src="clipart/pageHeaders/AbstactOlive.jpg" width="576" height="101" alt=""></div>      <div id="e3" style="position:absolute;left:190;top:108;width:546;height:25;"><span class="text"><b><font color="#666633" size="4"><span style="font-size:20px;line-height:24px;">Kind-Comp Data Input Tool<br soft></span></font></b></span>      </div>
      <div id="e4" style="position:absolute;left:1;top:147;width:163;height:334;"><!--$navbar 
name=navbar.nav
assetID=%NavbarAsset:/navigation_bars/navbar.nav
$--><!--$begin exclude$--><table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="index.html"><img name="i5" src="sitebuilder/images/navbar-0-inactive-39952.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="aboutus.html"><img name="i6" src="sitebuilder/images/navbar-1-inactive-40139.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="services2.html"><img name="i7" src="sitebuilder/images/navbar-2-inactive-40217.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="kindness_competition.html"><img name="i8" src="sitebuilder/images/navbar-3-inactive-40342.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="products.html"><img name="i9" src="sitebuilder/images/navbar-4-inactive-40436.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="Awards.html"><img name="i10" src="sitebuilder/images/navbar-5-inactive-44234.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="nhpc_IP.html"><img name="i11" src="sitebuilder/images/navbar-6-inactive-90359.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="pro_affiliations.html"><img name="i12" src="sitebuilder/images/navbar-7-inactive-39364.png" border="0" width="163" height="22" alt=""/></a></td></tr><tr><td height="17" width="0"> <img src="" height="17" width="1" alt=""></td></tr><tr><td><a href="contactus.html"><img name="i13" src="sitebuilder/images/navbar-8-inactive-81422.png" border="0" width="163" height="22" alt=""/></a></td></tr></table><!--$end exclude$-->      </div>
      <div id="e14" style="position:absolute;left:397;top:45;width:250;height:34;"><span class="text"><b><i><font size="2"><span style="font-size:14px;line-height:17px;">Innovative Product Development<br soft></span></font></i></b></span>      </div>
      <div id="e15" style="position:absolute;left:316;top:10;width:413;height:59;"><span class="text"><b><font size="5"><span style="font-size:24px;line-height:29px;">New Hope Products Company, Inc.<br soft></span></font></b></span>      </div>
      
<div id="e16" style="position:absolute;left:177;top:147;width:397;height:745;"><script type="text/javascript">
function checkForm16() {
  return true;
}
</script>
<form style="margin-top:0;margin-bottom:0;" name="Form16" method="POST" action="test.php" onSubmit="return checkForm16()">
<?php
$temp = $_SESSION['Num_Part'];
echo "<table border='1'>";
echo "<tr><th colspan='2'>Please enter your competition results.</th></tr>";
echo "<tr> <th>Participant Name</th> <th>Challenge Result</th> </tr>";
$count =1;
while ($count <= $temp){
  echo "<tr><td valign ='top'>"; 
  $temp2 = "Participant_P".$count;
  echo "<input name=$temp2 type='text' value=$temp2 size='20' />";
  echo "</td><td valign ='top'>"; 
  $temp3 = "Result_P".$count;
  echo "<input name=$temp3 type='text' size='15' />";
  echo "</td></tr>";
  $count++;
}
echo "</table>";
echo "<br/>";
//echo $temp. "<br/>";
?>
<input type="submit" value="Submit">

</form>
</div>


<!--$begin exclude$-->
    </div>
<!--$end exclude$-->
  </body>
</html>

Link to comment
Share on other sites

I already did this in the past and they are there at the end of the calling file and then gone in the next file called (test.php) by the Submit button action.

 

So (to me) it appears like the Submit button is causing the problem.  I'm wondering if there is a problem because I edited the original form code I created in Sitebuilder that uses their <form within their <div id...

 

???

 

I'm kind of confused about where exactly I need to place the session_start()...

Do I only need it once before I begin to create session variables or does it need to be placed at the beginning of each called file that uses the session variables?  I have tried it both ways and it did not change my problem.  But I would appreciate a clarification on this.  I wonder by using multiple times where it has some ill affect.

 

Not sure where to go from here.  I guess I should start skipped entire files and see whether a particular file is causing the problem.

 

 

 

Link to comment
Share on other sites

I understand the first requirement, but not sure what you mean by the second.  Do you mean it needs to be added into any file that subsequently creates new pages that use SESSION variable data?

 

In my case here I have placed session_start() at the beginning of all my files.  I guess my question next is - can it be used in error.  Meaning - if I have it in a file where it should not be, does this then restart the session, so this is why my session variables are being killed?

 

Should it not be used in a file that is called after one that has it - if that next file does not print to the browser?

Link to comment
Share on other sites

If you call session_start() after anything has been sent to the browser, the session won't be started, and a "headers already sent" warning will be generated. Which brings me to the next point, do you have error_reporting at -1 and display_errors set to On in your php.ini file while developing?

Link to comment
Share on other sites

 

$_SESSION variables do not work in some environments.  If you try to use them on these SMF boards, they may work in IE but not in FF, because SMF uses a different method to handle variables.  And, yes, you must have session_start() at the top of any file that uses the variables.

 

 

Link to comment
Share on other sites

I don't see anything in there that would be a likely cause of the problem. You're going to need to start inserting echos and figure out exactly where the values are being lost.

is a good habit to insert quote within value of the html tags

eg. value=$temp2 to value="$temp2" would avoid some unwanted problem in html output.

Ted

Link to comment
Share on other sites

If you call session_start() after anything has been sent to the browser, the session won't be started, and a "headers already sent" warning will be generated. Which brings me to the next point, do you have error_reporting at -1 and display_errors set to On in your php.ini file while developing?

 

Yahoo! does not allow us to access our php.ini file.  I have written their tech support to ask them what my settings are set to.

Link to comment
Share on other sites

 

$_SESSION variables do not work in some environments.  If you try to use them on these SMF boards, they may work in IE but not in FF, because SMF uses a different method to handle variables.  And, yes, you must have session_start() at the top of any file that uses the variables.

 

I use Firefox as a browser, but I'm not developing within a Simple Machine Forum platform.

Link to comment
Share on other sites

The information that Krash posted was probably due to specific problems he was having and are not generally applicable to anything else and in fact since he specifically mentioned SMF and that has nothing to do with what you are doing, I would suggest that he didn't even read your thread before replying.

 

There's nothing special about what you are doing. There are millions of web sites using session variables that work.

 

You should be developing your code on a local development system, where you would have the ability to modify the settings in the master php.ini. You can also set the error_reporting/display_errors settings in a .htaccess file (when php is running as an Apache Module), in a local php.ini (when php is running as a CGI application), or even in your script (though this won't show fatal php parse errors because those occure before you script runs and the statements to set error_reporting/display_errors are never executed.)

Link to comment
Share on other sites

I have isolated the problem to a specific action.  When the user selects a SUBMIT button from a 2nd form the session variables are lost then.

 

They are there while the form page is created.

 

They are there if I skip creating this page.

 

The same file I use to test whether the variables are there or not works fine if I skip this file or call it at the end of this file - meaning the session variables are there and OK.

 

But if I call this file from the action of the SUBMIT then the session variables are gone.

 

Does this point to anything specific?

Link to comment
Share on other sites

To see what the settings are, you can just create a new script with the following three lines of code in it, upload it and call it into your browser. It should generate a rather lengthy list of all the settings, etc.

 

<?php
phpinfo();
?>

Link to comment
Share on other sites

It's the file I posted previously.

 

Also I'm on with Yahoo! tech support and they are telling me that there is php error reporting.  They send all error messages to a scripts.log file in a log folder.  That folder did not exist, so they are doing some php testing on my account now.  Hopefully I will be able to access error messages for you soon.

Link to comment
Share on other sites

If I might make a suggestion, it would be infinitely easier for you to develop and test locally, then when the script functions properly upload it to the live site. You can install Apache, php and MySQL as a package with WAMP or XAMPP (or similar depending on what OS you use).

Link to comment
Share on other sites

I hear you and may very well need to invest the time and effort into this - as I'm wasting too much time here.

 

BTW - Yahoo! tech support tells me the php is working fine and the errors are being dumped to that file now.  I ran my script and I'm seeing no new messages dumped there.  So can I assume my script is not creating any errors?  Something else must be killing my session variables???

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.