PDA

View Full Version : Session variables being lost



werribeecc.net
06-07-2008, 09:01 PM
Hi, and thank you to all who take time to read my problem.

I am in the proccess of xfering our website from our old host to hostmonster. On our old host there were no problems with the enrolment form working that I created, now that I have xfered the site to hostmonster this form does not function correctly. Basically the enrolment form is a step by step form which passes the value selected on the previous page to the next page via session variables. On the old host these values would pass along to each page without any problems, on hostmonster these variables are not being passed along, the problem can be viewed at the following address www.werribeecc.net/enrol1.php.

Here is the code for the first page


<?php

ini_set('session.use_only_cookies',1);
session_start();
session_register("SESSION");

$_SESSION['courseValue']="";
$_SESSION['day'];

?>

Further down on the same page I have a bit of code which fetchs a php form


<?php
include("enroltext/Enrol-Online1.php");

?>

Here is the code contained in Enrol-Online1.php


<FORM ACTION="enrol2.php#bottom" METHOD="POST" ENCTYPE="multipart/form-data" onSubmit="return ValidForm(this);">

?php

echo "<select name=\"r_Course_Name\" title=\"Course_Name\">";
echo "<option value=\"\" selected>Select Course From menu</option>";
$text2 = file_get_contents("coursename.txt");
$array2 = explode("\n",$text2);
foreach ($array2 as $key => $value){
echo "<option value='$value'>$value</option>";
}
echo "</select>";
?>
<INPUT TYPE="SUBMIT" VALUE="Next">
<input type="hidden" name="hiddenField" id="hiddenField">
</FORM>

I have contacted support and they say that my code should work. I am certainly no expert when it comes to php more like a beginner, but the form worked fine before maybe someone here can suggest why it may not be working on hostmonster.

Thank you in advance to those who take the time to respond.

pghcollectibles
06-08-2008, 01:05 AM
is there a reason you are only doing one option per page? after enrol25.php i got bored so i stopped looking but on each page you could use something like:

<?php
$r_Course_Name=$_POST['r_Course_Name'];
//do some form validation with php here
?>

then later...

<?php
echo "<select name='r_Course_Name' title='Course Name'>"
echo "<option value='" . $r_Course_Name . "' selected>" . $r_Course_Name . "</option>";
echo "</select>";

etc...

the form validation is not very good. Also, it would be good if you had a line of code at the beginning of each page checking to see how you got there for example in enrol2.php the first lines would be:

<?php
if !($HTTP_REFERER=="http://www.werribeecc.net/enrol1.php") {
echo "<html><head><meta http-equiv='Refresh' content='0;url=http://www.werribeecc.net/enrol1.php' /></head><body></body></html>";
die();
}
?>that could be done with .htaccess quicker than editing all those pages though.

personally, i'd make one form on one page and use form validation that reflects your expected answers

werribeecc.net
06-08-2008, 02:09 AM
The reason I have done it page by page is to ensure that previous selections are not inadvertantly changed. The form has worked for its purpose as is, i'm not really looking at ways to change the form.

What my problem is that on my previous host this form worked correctly by carrying the session variables from one page to another, on hostmonster this is not happening previous selections are appearing as blank. Here is the address of my previous host http://67.15.120.15/werribeecc.net/enrol1.php as you can see the form is working as it should.

pghcollectibles
06-08-2008, 11:59 AM
the form action takes me to http://www.werribeecc.net/enrol2.php#bottom with form.r_Couse_Name.value="" if thats not where it takes you then you might have to clear your cache

yes it is true. results:

Compare: (<)C:\tests\67.15.120.15/werribeecc.net/enrol1.txt (8227 bytes)
with: (>)C:\tests\www.werribeecc.net/enrol1.txt (http://www.werribeecc.net/enrol1.txt) (8227 bytes)

The files are identical

is this just a typo?:

"
Here is the code contained in Enrol-Online1.php

Code:
<FORM ACTION="enrol2.php#bottom" METHOD="POST" ENCTYPE="multipart/form-data" onSubmit="return ValidForm(this);">

?php

echo "<select name=\"r_Course_Name\" title=\"Course_Name\">";
echo "<option value=\"\" selected>Select Course From menu</option>";
$text2 = file_get_contents("coursename.txt");
$array2 = explode("\n",$text2);
foreach ($array2 as $key => $value){
echo "<option value='$value'>$value</option>";
}
echo "</select>";
?>
<INPUT TYPE="SUBMIT" VALUE="Next">
<input type="hidden" name="hiddenField" id="hiddenField">
</FORM>
I have contacted support and they say that my code should work.
"

there is a line: ?php
that should be <?php

i guess it must be as its not messed up in the browser


ok ignore that. the code that i see so far is just for the front page which looks like it works and has to send form data to enrol2.php but...

i would need to see the code that is receiving the post or session variables and applying them to that page's form. you have a session variable named courseValue but a form variable named R_Course_Name

i guess i see the form submit button pressed, then
function ValidForm(form) would either come back true or not, but i dont have the code that tells me what is happening next.

i need more info to help i guess

werribeecc.net
06-08-2008, 06:48 PM
This is the code for enrol2.php

<?php

ini_set('session.use_only_cookies',1);
session_start();
session_register("SESSION");

$_SESSION['courseValue'] = $_POST['r_Course_Name'];
$_SESSION['day'] = $_POST['r_Day'];

?>

And further down again code to fetch the form


<?php
include("enroltext/Enrol-Online2.php");

?>

The function ValidForm(form) is a javascript function that validates that data is selected before moving to the next page


<SCRIPT LANGUAGE = "JavaScript">
function isFilled(str){ return (str != ""); }
function isEmail(str) { return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); }
function isDigital(str) { return(parseFloat(str,10)==(str*1)); }
function isCurrency(val) { var re = /^(\$?\d+\$?|\$?\d+\.\d+\$?)$/; return (re.test(val)); }
function ValidForm(form) {
var field, i;
var req = new Array(1);
var email = new Array(0);
var digits = new Array(0);
var currs = new Array(0);
req[0] = "r_Day";

for (i=0;i<1;i++) {
eval("field = form." + req[i]);
if (!isFilled(field.value)) {
alert("Field '" + field.title + "' is required to be filled in before successful submission.");
field.focus();
return false;
break;
}}
for (i=0;i<0;i++) {
eval("field = form." + email[i]);
if (!isEmail(field.value)) {
alert("Field '" + field.title + "' is required to be filled in with valid email addresses before successful submission.");
field.focus();
return false;
break;
}}
for (i=0;i<0;i++) {
eval("field = form." + digits[i]);
if (!isDigital(field.value)) {
alert("Field " + field.title + " is required to be filled in only with digits (0-9) and decimal point before successful submission.");
field.focus();
return false;
break;
}}
for (i=0;i<0;i++) {
eval("field = form." + currs[i]);
if (!isCurrency(field.value)) {
alert("Field " + field.title + " is required to be filled in only with digits (0-9) a decimal point, or a dollar sign before successful submission.");
field.focus();
return false;
break;
}}
return true; }

</SCRIPT>

r2b2
06-08-2008, 07:46 PM
Maybe I'm missing something but it seems to work fine for me? Maybe you've got cookies disabled or something?

werribeecc.net
06-08-2008, 08:13 PM
I just got done fixing the problem. In the original script I could use $courseValue to call the session variable, for some reason on host monster I had to adjust the script to assign $_SESSION['courseValue'] to $courseValue maybe a php 4 versus php 5 thing?

Anyway its fixed now, thank you to all who tried to help with this problem it is greatly appreciated.

r2b2
06-08-2008, 08:23 PM
Nope - it will be that register_globals was on by default on your previous host and is turned off by default on HostMonster.

This is a good thing as using scripts with register_globals turned on is a very dangerous thing.

So in the course of fixing up your script, you've now increased your level of security as well :D