Solved

Passing Session variable not working

Posted on 2010-08-13
5
302 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:tekguy2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 250 total points
ID: 33429304
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
 
LVL 11

Assisted Solution

by:Pieter Jordaan
Pieter Jordaan earned 250 total points
ID: 33429328
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
 

Author Comment

by:tekguy2001
ID: 33430872
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
 
LVL 11

Expert Comment

by:Pieter Jordaan
ID: 33430914
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
 

Author Closing Comment

by:tekguy2001
ID: 33431004
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

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question