Page 1 of 1

session variable

Posted: Wed Feb 25, 2004 1:24 pm
by tanmy_1999
Hello all,
I am not able to set the session variable. on the firstpage.php

Code: Select all

<?php
session_start();
?>
<?php
//print("<form method=post action=thispage.php>");


//goes here whne the student hits submit
if(isset($student_number))
&#123;
	print("<form method=post action=thispage.php>");
	$file_name = file('student_number.txt');
	//check the student number
	for ($i=0; $i<count($file_name); $i++) 
	&#123; 
		if(!strcmp($student_number_value+"",$file_name&#1111;$i]+""))
		&#123;
			$valid_student_no='1';
			$student_number = $student_number_value;
			print("$student_number");
			break;
		&#125;
		else
		&#123;
			$valid_student_no='0';
		&#125;
	&#125; 
	
&#125;
if($valid_student_no=='0')
&#123;
	print("Invalid student number, redirecting you to proper page.");
	session_unset(); 
    //session_destroy(); 
?>
<head>
<meta HTTP-EQUIV="REFRESH" content="1; url=someurl">
</head>
<?php
&#125;
else if($valid_student_no=='1') &#123;
	print("Please wait redirecting...");
	?>
	<head>
<meta HTTP-EQUIV="REFRESH" content="1; url=nextpage.php">
</head>
<?php
&#125;

else&#123;
print("<form method=post action=brooks.php>");
//first page that the users will encounter.
$_SESSION&#1111;'valid_student_no']="";
$_SESISON&#1111;'student_number']="";
?>

Please enter your student number: <input type= "text" name="student_number_value" maxlength="7">
<br><br>
<input type="submit" name="student_number" value="Submit"> &nbsp;&nbsp;&nbsp;<input type="reset">
<?php
print("</form>");
&#125;
?>
and nextpage.php

Code: Select all

<?php 
//start session
session_start();
	print("<form method=post action=nextpage.php>");
	print("Welcome to brooks system. $student_number");
	//mechanism to check if the profile is created or not.
	//depending on that give them the options. 
	
	 
	
?>
Both the pages have same sesion id's, on giving the corect student number the code goes to the nextpage, although on nextpage the value $student_number (session variable declared on firstpage.php) does not appear.

Help will eb appreciated..

Tanmay

Posted: Wed Feb 25, 2004 9:00 pm
by AVATAr
use $_SESSION['student_number'] allways if you are using it as a session variable not $student_number

Could this b the solution to your problem?

Posted: Tue Mar 02, 2004 8:10 pm
by cyberhawk
Check your php.ini and locate this:

session.use_trans_sid = 0

and change the 0 to 1:

session.use_trans_sid = 1

Then reboot your puter.

And 4 some code, have a look at my little test.

First page

Code: Select all

<?php 
session_start(); 

$un = "anders"; 

$_SESSION['uname']=$un; 
$_SESSION['ualias']='olle'; 
echo '<pre>'; 
print_r($_SESSION); 
echo '</pre>'; 
?> 

<p><a href="test4.php">Page 2</a></p>

Second page

Code: Select all

<?php 
session_start(); 

echo '<pre>'; 
print_r($_SESSION); 
echo '</pre>'; 

echo $_SESSION['uname']; 
echo $_SESSION['ualias']; 

?>