ICubis2 Posted April 8, 2011 Share Posted April 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/ Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 Assuming you've already made sure session_start() is called at the beginning of the script that is having the problem, please post the relevant code within . . . tags. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198799 Share on other sites More sharing options...
ICubis2 Posted April 8, 2011 Author Share Posted April 8, 2011 <?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 />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198804 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 That code isn't the problem. Is that all that's in that script? Do you have error_reporting set to -1, and display_errors set to On in your php.ini file? Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198809 Share on other sites More sharing options...
ICubis2 Posted April 8, 2011 Author Share Posted April 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198821 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 Yes, post the file that calls that one . . . Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198831 Share on other sites More sharing options...
ICubis2 Posted April 8, 2011 Author Share Posted April 8, 2011 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198865 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198877 Share on other sites More sharing options...
ICubis2 Posted April 8, 2011 Author Share Posted April 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198939 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 session_start() needs to be before any attempt to use $_SESSION variables, and before any output of any type is sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198975 Share on other sites More sharing options...
ICubis2 Posted April 8, 2011 Author Share Posted April 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1198986 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199021 Share on other sites More sharing options...
Krash Posted April 9, 2011 Share Posted April 9, 2011 $_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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199057 Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199186 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199237 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 $_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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199238 Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2011 Share Posted April 9, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199243 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 I have isolated the problem to a single file. I'm now trying to associate the code that is causing the problem. Stay tuned... Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199263 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199268 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199311 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 Yahoo! has error_reporting: no value and display_errors: off Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199321 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 Can you post the file that's causing the symptoms? Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199326 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199341 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 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). Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199344 Share on other sites More sharing options...
ICubis2 Posted April 9, 2011 Author Share Posted April 9, 2011 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??? Quote Link to comment https://forums.phpfreaks.com/topic/233094-session-variables/#findComment-1199349 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.