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!!

5
  • 1
    try renaming nextpage.html to nextpage.php Commented Sep 2, 2013 at 21:41
  • also its good practice to check if $_POST values are actually set before using. Commented Sep 2, 2013 at 21:43
  • The post values are set and getting checked, sorry I abridged the code, forgot to put that part in. @Tushar, is there any specific reason why the next page would need to be php instead of html? Commented Sep 2, 2013 at 21:47
  • 1
    That worked (changing it to .php), thanks so much!!!! I would love to know why, though :p Commented Sep 2, 2013 at 21:49
  • actuall if you wont mention the extention the browser wont understand where its a scripting language or not Commented Sep 2, 2013 at 21:59

1 Answer 1

2

The reason why you are having problems is that your header('Location: nextPage.html'); is pointing to an .html file.

Passing sessions from one page to another will only work under a PHP environment and should have been set as header('Location: nextPage.php');

However, .html files can run as PHP by using the following directives in .htaccess

AddType application/x-httpd-php .html

If you only plan on including the PHP on one page, it is better to setup this way:

<Files nextPage.html>
AddType application/x-httpd-php .html
</Files>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.