Link to home
Start Free TrialLog in
Avatar of tekguy2001
tekguy2001Flag for Canada

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tekguy2001

ASKER

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

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>";

?>
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.