I can't seem to see why the $_SESSION['email'] isn't being passed
Page 1 Segment
<?php
if (isset($finalusername, $finalpass, $finalemail)) {
$myFile = "users/$finalusername.txt";
$fh = fopen($myFile, 'w') or die("There was an error in creating your account. <br />");
$stringData = "$finalusername\n";
fwrite($fh, $stringData);
$stringData = "$finalpass\n";
fwrite($fh, $stringData);
$stringData = "$finalemail\n";
fwrite($fh, $stringData);
fclose($fh);
// set session variable
session_start();
$_SESSION['email'] = "$finalemail";
echo "<a href='emailverify.php'><button>Continue to Email Verification Page</button></a>";
}
?>
Page 2 Segment
<?php
// Check if your session variable is active
session_start();
if (isset($_SESSION['email'])) {
$message = rand(111111111, 999999999);
$to = "[email protected]";
$subject = "Test mail";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
session_start();
unset($_SESSION['email']);
}
?>
I really cant see what i've done wrong. I know everything else is eprfect because the rest of the code works.
session_start()should be always placed on the top of PHP scriptsession_start()always at the very beginning (just to be sure). Also the second call tosession_start()in the page 2 script isn't neccessary.