Session variables get lost when redirecting -PHP -
i new using php , trying build content management site.
i started developing login pages , @ start session variables kept normal , working without issues when using redirect page after login confirmed.
but 2 days ago tried develop forgot password functionality , since , changing output buffering enabled have issue. session variables not carried on redirected page , login doesn't work.
my code below:
<?php include("../includes/session.php"); ?> <?php require_once("../includes/db_connection.php"); ?> <?php require_once("../includes/functions.php"); ?> <?php require_once("../includes/validation_functions.php"); ?> <?php $username = ""; if (isset($_post['submit'])) { // process form // validations $required_fields = array("username", "password"); validate_presences($required_fields); if (empty($errors)) { // attempt login $username = $_post["username"]; $password = $_post["password"]; $found_admin = attempt_login($username, $password); //print_r($found_admin); if ($found_admin) { // success // mark user logged in $_session["admin_id"] = $found_admin["usr_serno"]; $_session["username"] = $found_admin["username"]; redirect_to("admin.php"); } else { // failure $_session["message"] = "username/password not found."; } } }else if(isset($_post['forgot'])) { redirect_to("forgotpassword.php"); } ?> <?php $layout_context = "admin"; ?> <?php include("../includes/layouts/header.php"); ?> <div id="main"> <div id="navigation"> </div> <div id="page"> <?php echo message(); ?> <?php echo form_errors($errors); ?> <h2>login</h2> <form action="login.php" method="post"> <p>username: <input type="text" name="username" value="<?php echo htmlentities($username); ?>" /> </p> <p>password: <input type="password" name="password" value="" /> </p> <input type="submit" name="submit" value="submit" /> <input type="submit" name="forgot" value="forgot password" /> </form> </div> </div> <?php include("../includes/layouts/footer.php"); ?>
the session.php starts session , admin.php check if session[admin_id] isset show page or else redirect again login.php page, happens.
any advise or please?
Comments
Post a Comment