0

i have a $_sesstion['usermail']. i want to pass this value to next page.if condition match ($answer= $_SESSTION['usermail']);

if(isset($_POST['compair']))
{

    echo $_SESSION['question'];
     $_SESSION['usermail'];
    $answer=$_POST['answer'];
    if ($answer ==  $_SESSION['answer'])
    {
         header("Location:resetpass.php");

    }
    else
    {
         echo "<script>alert('Please Try again')</script>";

    } 

}

i want to pass $_sesstion['usermail'] value on resetpass.php page.

Sachith Wickramaarachchi
  • 5,546
  • 6
  • 39
  • 68
Brij Sharma
  • 361
  • 6
  • 19
  • Did you do a `session_start()` in that code somewhere? – RiggsFolly Apr 19 '17 at 17:42
  • That code is a bit of a mess. Start by adding [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Apr 19 '17 at 17:44
  • The [PHP manual may also help you understand SESSIONS](http://php.net/manual/en/book.session.php) – RiggsFolly Apr 19 '17 at 17:45
  • yes i start session in both pages. – Brij Sharma Apr 19 '17 at 17:45

4 Answers4

2

I think your logic is wrong here. What exactly are you checking in the if statement. A session variable means you can use it on every page that has session_start(); on top.

  • actually i am creating page to reset password with help of security question method in this page i trying to match answer of the question from database to user entered if match then jump to the resetpass.php page other then show error message. – Brij Sharma Apr 19 '17 at 17:53
1

Sessions by default pass to other pages. Make sure you have start_session(); on top of the page you want to access the session variable.

So if $_SESSION['usermail'] is working on your current page, it'll work on your next as well with same data.

Simos Fasouliotis
  • 1,383
  • 2
  • 16
  • 35
1

Get an idea from this exmple

First Page

<?php 
session_start();    

$_SESSION['name'] = "Adam"; 

?>

Second page

<?php 
session_start();    

echo $_SESSION['name'];
?>
Vimukthi Guruge
  • 285
  • 3
  • 15
1

You can use GET methods for sharing your session value to next page...

if(isset($_POST['compair']))
{

echo $_SESSION['question'];
 $_SESSION['usermail'];
$answer=$_POST['answer'];
if ($answer ==  $_SESSION['answer'])
{
     $value_to_share=$_SESSION['usermail']; // You can share using GET
     header("Location:resetpass.php?value=$value_to_share"); 
    // receive this value at resetpass.php by $_GET['value'] 

}
else
{
     echo "<script>alert('Please Try again')</script>";

} 

}

coder007
  • 11
  • 3