我似乎无法理解为什么$_SESSION['email']
没有被传递
<?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>";
}
?>
<?php
// Check if your session variable is active
session_start();
if (isset($_SESSION['email'])) {
$message = rand(111111111, 999999999);
$to = "email@email.com";
$subject = "Test mail";
$from = "email@email.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
session_start();
unset($_SESSION['email']);
}
?>
我真的不知道我做错了什么。我知道其他一切都是完美的,因为其余的代码都可以工作。
答案 0 :(得分:3)
“session_start()
在PHP中用于在每个PHP页面上启动会话。它必须是发送到浏览器的第一件事,否则它将无法正常工作,所以通常最好将其放在后面<?php
标记。这必须在您打算使用会话的每个页面上。“