0

first of all, I found several other questions, but nothing helped me so far. Quick question: I lose my session-variables after a redirect. Check this:

Login.php

if(preg_match("/[a-zA-Z]{2}\d{2}/im", $_POST["foo"])) {
    if($_POST["email"]) {
        $aPieces = explode("@", $_POST["email"]);
        if(in_array($aPieces[1], $aAllowedMails)) {
            session_start();
            $_SESSION["isAllowed"] = true;
            header("Location: start.php");
            exit;
        }
    }
}

Start.php

<?php
    // session_start()
    if($_SESSION["isAllowed"] == true) : 
?>
some content

<?php else : ?>

<h1>Acces Denied</h1>

<?php endif ?>

my session is always NULL on the 2nd page (start.php), which leads to the "access denied"-text. Tried to add the 2nd session_start as well on start.php, but that ends up with the error-message:

session_start(): Cannot send session cache limiter - headers already sent > (output started at [path]/start.php:1) in Any ideas?

DasSaffe
  • 2,080
  • 1
  • 28
  • 67

1 Answers1

1

Do you start the session on the next page? If you don't, you can do this by adding this to your code:

<?php session_start(); ?>
<?php
    if($_SESSION["isAllowed"] == true) : 
?>
some content

<?php else : ?>

<h1>Acces Denied</h1>

<?php endif ?>
Jan-Willem de Boer
  • 797
  • 10
  • 19