, [code], and [quote] tags where appropriate. [/COLOR][/B]
I have a php script that passes session data to itself (it's a single page that changes through a series of steps.) Anyway, there is an include file that it uses as well.
The problem is that randomly, the session variable will get unset and will go back to the first step because of this. The ONLY section of code where this variable gets unset, is not being executed... Sometimes it will happen 1/7 times, sometimes it will happen 1/21 times. It doesn't depend on the user input at all either.
Thanks for the help! Below is some sample code (the variable in question is the $_SESSION['count'] variable):
[B]HTACCESS:[/B]
[code]php_flag session.use_only_cookies on
php_flag session.use_trans_sid off
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blender/
#RewriteCond %{REQUEST_FILENAME} index\.php
RewriteCond %{REQUEST_FILENAME} !blender_control\.php
RewriteCond %{REQUEST_FILENAME} !blender_redirect\.php
RewriteCond %{REQUEST_FILENAME} !\.gif
RewriteCond %{REQUEST_FILENAME} !\.jpg
RewriteCond %{REQUEST_FILENAME} !\.png
RewriteCond %{REQUEST_FILENAME} !\.css
RewriteCond %{REQUEST_FILENAME} !\.swf
RewriteCond %{REQUEST_FILENAME} !\.inc
RewriteCond %{REQUEST_FILENAME} !\.dat
RewriteCond %{REQUEST_FILENAME} !\.txt
RewriteCond %{REQUEST_FILENAME} !\.js
RewriteRule . /blender/blender_control.php [L]
</IfModule>[/code]
[B]The Include File[/B][php]
<?php session_start();
.
.
.
function showQuestion($i) {
global $numquestions, $q, $a, $mchoice;
echo "<form method=POST ><br>";
echo "<input type=hidden name=next value=$i >";
echo "<input type=hidden id=idSelection name=selection value=-1 >";
echo "<table cellpadding=1 ><th halign=left colspan=2 > <h2 align=center>$q[$i]</h2> <br></th>";
$mylist = split (";", $mchoice[$i]);
$j=0;
foreach ($mylist as $keys => $values) {
$id="rdo".$j;
echo "<tr ><td align=right valign=center size=40% > <input type=radio id=rdo0 name=$i value='$values' onClick='onClickRadio($j)'></td>";
echo "<td align=left valign=center size=60% ><h1> $values </h1></td></tr>";
$j++;
}
echo "<tr><td colspan=2 align=center ><br><input type=image src=images/submit.gif name=Continue value=Continue onClick='onClickContinue()' \> </td></tr></table>";
};
.
.
.
?>[/php]
[B]The main script[/B][php]
<?php session_start();
.
.
.
if (isset ($_SESSION['count'])) {
$_SESSION['count'] = $_SESSION['count'] + 1;
}
else {
$_SESSION['count']=1;
$_SESSION['score']=0;
$_SESSION['maxscore'] =0;
};
.
.
.
#--- check if user submitted form --#
elseif (isset($_POST["next"])) {
$_SESSION['score'] += calculateScore($_SESSION['count'] - 1);
//numquestions is a constant by the way..it doesn't change..
if ($numquestions >= $_SESSION['count'] ) {
if($numquestions > $_SESSION['count']) {
echo "<h3>Question " . $_SESSION['count'] . " of 10</h3 >\n";
}
showQuestion($_SESSION['count']);
}
}
else { #show first question
echo "<h3>Question 1 of 10</h3 >";
showQuestion(1);
$_SESSION['count'] = 1;
}
.
.
.
elseif (isset ($_POST['var'])) {
//not being executed. it would make sense if it was...
echo "<script type=\"text/javascript\"> checkPop(); </script>";
include ("blah.php");
#---- reset session vars ---#
unset ($_SESSION['count']);
unset ($_SESSION['max']);
unset ($_SESSION['score']);
}
[B]John | [COLOR="Red"]Please use [php], [code=auto:0], and [quote] tags where appropriate.
Edited by John, 10 January 2009 - 12:09 PM.