...

View Full Version : Sending variable from one php file to another



eon201
10-31-2007, 11:25 AM
Hi this is pretty noob stuff but here goes!

Ok so I have two php files.
a.php
b.php

a.php deals with some form validation, ending in


$worked = mail($to, $title, $message, $headers);

if($worked) {
$confmsg = '<p>Your request for a call back has been sent. A Cruise Specialist will be in touch.</p><p>You will now be redirected back to the page you were previously viewing. If the page does not load shortly please <a href="' . $prev . '">click here</a>.</p>';
// Insert monitor forwarder here
}
else {
// It failed
$confmsg = '<h1 class="first">Registration Problem</h1><p>There was a problem with your registration, please try again later.</p><p>You will now be redirected back to the page you were previously viewing. If the page does not load shortly please <a href="' . $prev . '">click here</a>.</p>';
}
?>
<?php session_start();
$_SESSION['$worked'] = $_POST['$worked'];
?>

Whilst b.php takes the session checks to see if the mail has been sent and if so posts an echo like so:


<?php session_start();
$callback = $_SESSION['$worked']
?>
<?php
if ($callback) {
// Received new callback submission
$callmsg = '<p>We have received a new callback request</p>';
}
else {
//Did not recive new callback submission
$callmsg = '<p>There are no new callback requests</p>';
}
?>
<?php echo $callmsg; ?>


But it doesnt work??? Why is this? What am I not understanding about sessions?

Thanks in advance. eon201

eon201
10-31-2007, 12:28 PM
Ok ive found out that I should be using sessions for this as it would make my life easier when calling a variable later on in any file. Has anyone get experience with this??

Thanks. Eon201

mlseim
10-31-2007, 02:20 PM
You need to write the session, then go back to your script (redirect),
or refresh your page (if it's within the same script). Like cookies, there needs
to be that one extra refresh to send the header.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum