Passing Session variable not working

Hi everybody,

could you tell me why my session variable is not working?  I've attached part of the code im using.

File 1 (Creates a random number and displays it as a picture)
File 2 (Pull Session variable for validation)

The whole script works fine except for that session variable not being able to be passed.

<?php
session_start(); 
$_SESSION['rand'] = rand(10000, 99999);
$image = imagecreate(60, 30);
$bgColor = imagecolorallocate ($image, 255, 255, 102); 
$textColor = imagecolorallocate ($image, 0, 0, 0); 
imagestring ($image, 5, 5, 8, $_SESSION['rand'], $textColor); 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 

header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 

header("Pragma: no-cache"); 

header('Content-type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
?>

Open in new window

<?php
session_start();

$mailto = 'steve@remotely-connected.com' ;

$subject = "Feedback Form" ;

$formurl = "http://www.nationalrepocenter.com" ;
$errorurl = "http://www.remotely-connected.com/error.html" ;
$thankyouurl = "http://www.remotely-connected.com/ty.html" ;

$email_is_required = 1;
$name_is_required = 1;
$telephone_is_required = 1;
$password_is_required = 1;
$uself = 1;
$use_envsender = 0;
$use_sendmailfrom = 0;
$use_webmaster_email_for_from = 0;
$use_utf8 = 1;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
	ini_set( 'sendmail_from', $mailto );
}
$envsender = "-f$mailto" ;
$fullname = $_POST['fullname'];
$company = $_POST['company'];
$address = $_POST['address'];
$email = $_POST['email'] ;
$telephone = $_POST['telephone'];
$fax = $_POST['fax'];
$chapka = $_POST['password2'] ;
$give = $_SESSION['password'];

$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
	header( "Location: $formurl" );
	exit ;
}
if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($telephone_is_required && empty($telephone)) ) {
	mail($mailto, $subject, $messageproper, $headers, $envsender );
	mail($mailto, $subject, $messageproper, $headers, $envsender );
	header( "Location: $errorurl" );
	exit ;
}
if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {
	mail($mailto, $subject, $messageproper, $headers, $envsender );
	header( "Location: $errorurl" );
	exit ;
}

if (empty($email)) {
	$email = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;


$messageproper =
	"This message was sent from:\r\n\r\n" .
	"-----REMOTELY CONNECTED WEBSITE --------------------------------\r\n" .
	"\r\n" .
	"Sender's name:          $fullname\r\n" .
	"Sender's Company:       $company\r\n" .
	"Sender's Address:       $address\r\n" .
	"Sender's Email address: $email\r\n\r\n" .
	"Sender's Phone number:  $telephone\r\n".
	"Sender's Fax number:  $fax\r\n".
	"$chapka || $give  \r\n\r\n" .	"\r\n\r\n--------------------------------------------------------------\r\n" ;

$headers =
	"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
	$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

if ($use_envsender) {
	mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
	mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;

?>

Open in new window

tekguy2001Asked:
Who is Participating?
 
Beverley PortlockConnect With a Mentor Commented:
I'm confused. In file1 you use $_SESSION['rand'] and in file2 you use $_SESSION['password']

There is no session information in common other than the session itself and sessions have no data unless you put it in there.
0
 
Pieter JordaanConnect With a Mentor Senior Systems Administrator - Web hosting and Network Security.Commented:
Hi

Place the attached code at the bottom of each page.
This will display the contents of $_SESSION

Please post the output.
debug($_SESSION);

function debug($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}

Open in new window

0
 
tekguy2001Author Commented:
Sorry, I just fixed that and it still doesn't work.  Can a hosting site disable that feature in PHP?  I've followed everything to the letter and it still doesn't work.  I've also put that code from  bitfreeze and it doesn't display anything.  I've also created a test.php which is called from the form and it has the following code

It should work no?  It should at least shwo the variable.
<?php
session_start();
echo ('here');
echo $_SESSION['rand'];
print_r($array);
echo "</pre>";

?>

Open in new window

0
 
Pieter JordaanSenior Systems Administrator - Web hosting and Network Security.Commented:
Lets just check if it can save and retrieve a value.

<?php
session_start();

$_SESSION['testentry'] = "working";
echo $_SESSION['testentry'];

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

?>
0
 
tekguy2001Author Commented:
Thanks to you both, but it looks like the Host provider disabled the option...  Grrr.  Well it's all fixed and working now, thank you.
0
All Courses

From novice to tech pro — start learning today.