Solved

Passing Session variable not working

Posted on 2010-08-13
5
299 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now