0

I know this has been asked many, many, many times; however, the various things I have seen and tried have not worked.

All I want to do is pass data from one page to the next, so I can use the user's email to do various Database things.

Here's my login.php file (abridged, only showing the login stuff) :

<?php
session_start();

ini_set("display_errors", "1");

$user_email = $_POST['user_email'];
$_SESSION['user_email'] = $user_email;

$password = $_POST['user_password'];

//DB stuff

if ($num_results == 1) {

header('Location: nextPage.html');
exit;
}

else {

echo "<p> Username or Password is incorrect! </p>";
}
?>

Here is my next page html file:

<?php
session_start();

ini_set("display_errors", "1");

$email = $_SESSION['user_email'];

echo $email;
?>


<html>
<head>
<title> next page </title>
</head>

<body>

You have logged in!
</body>
</html>

Whenever I try to echo the email it is blank, and when I test for it, it tells me that it is empty.

Any advice would be helpful, thanks so much!!

4

1 回答 1

2

您遇到问题的原因是您header('Location: nextPage.html');指向一个.html文件。

将会话从一个页面传递到另一个页面只能在 PHP 环境下工作,并且应该设置为header('Location: nextPage.php');

但是,.html文件可以通过使用以下指令作为 PHP 运行.htaccess

AddType application/x-httpd-php .html

如果您只打算在一页上包含 PHP,最好这样设置:

<Files nextPage.html>
AddType application/x-httpd-php .html
</Files>
于 2013-09-03T01:19:36.360 回答