1

Firstly, I have searched many threads and topics and they all keep saying its function placement but thus far I do not see a issue with my placement. I am desperate to get this is working because I am SICK of looking at 50+ extra lines of repetitive code.

resetpassword.php (RELEVANT CODE):

<?php
        require_once $_SERVER['DOCUMENT_ROOT'] . '/php/security/sslcheck.php';

        $ResetID = $_GET["ID"];

        session_start();
        require_once $_SERVER['DOCUMENT_ROOT'] . '/php/functionality/error.php';
        print_r(array_values($_SESSION));

        if(empty($ResetID) && !isset($_SESSION["ERR"]) && !isset($_SESSION["ERR_MSG"])) {
            $ResetPassword = "REQUEST";
            if(isset($_POST["email-search"]) && !empty($_POST["email-search"])) {
                require_once $_SERVER['DOCUMENT_ROOT'] . '/php/functionality/users/request.php';

                // Start Request Process
                $Request = RequestPasswordReset($_POST["email-search"]);

                if($Request === "USER_NOT_FOUND") {
                    DisplayError("Password Reset Request Failed", "The specified email is not tied to any accounts in our system.", "/account/resetpassword.php");
                } else if ($Request === "MAIL_FAILURE") {
                    DisplayError("Password Reset Request Failed", "Failed to email you the password reset email.", "/account/resetpassword.php");
                } else {
                    DisplayError("Password Reset Request Success", "We have sent a email that contains a link to reset your password.", "/account/resetpassword.php");
                }
            }

More Relevant Code

            <?php
            if (isset($_SESSION["ERR"]) && isset($_SESSION["ERR_MSG"])) {
                echo '<div id="resetPasswordStatus">';
                echo '<h4>' . $_SESSION["ERR"] . '</h4>';
                echo '<p>' . $_SESSION["ERR_MSG"] . '</p>';
                echo '</div>';
                session_destroy();
            }
        ?>

error.php (ALL CODE):

<?php
  session_start();
  function DisplayError($title, $body, $returnlink) {
      $_SESSION["ERR"] = $title;
      $_SESSION["ERR_MSG"] = $body;
      header("Location: " . $returnlink);
  }
?>

I have experiment in many ways with my placement of require_once of error.php, but have found no luck. I understand $_SESSION is a superglobal and require or require_once copy the code right into place where required. However even copying error.php manually into resetpassword.php I was unable to get the function to work. Thank you guys for your help as it really means a lot!

The expected output is after the callback after the request for a password reset, is the alert to display. Code for this alert can be seen under More Relevant Code.

4
  • Look at your code, your first if statement !isset($_SESSION["ERR_MSG"] your function is never getting called Commented Oct 28, 2017 at 17:53
  • The idea is when I submit a password request, it would perform it and then call back to the same page with a session describing a error/alert. The More Relevant Code I just added shows the displaying of the call back. The issue is that the call back wont work and if I check $_SESSION vars, the ERR & ERR_MSG variables have NOT been sent. Commented Oct 28, 2017 at 18:00
  • does var_dump($_SESSION["ERR"]) in your DisplayError function gave expected result? i mean, the problem is the superglobal itself, or the header. perhaps an expected output is to be stated in the question more clearly. Commented Oct 28, 2017 at 18:06
  • @BagusTesa I have done print_r(array_values($_SESSION)) and nothing is returned. Commented Oct 28, 2017 at 18:10

2 Answers 2

2

Solution:

In the error.php if you add exit(); after the header redirect it allows for PHP to pause execution while the redirect occurs which prevents the error displaying code from running its code and then wiping the session which leaves the redirect empty in terms of sessions.

Sign up to request clarification or add additional context in comments.

Comments

0

You are calling the function after the if statement empty($ResetID) Your function isn't running if the $_GET['ID'] is not empty so change it to !empty($ResetID)

7 Comments

Read the comments, there is a request and then a call back!
what is the return for var_dump($_SESSION);
I have done print_r(array_values($_SESSION)) and nothing is returned. @PaulE
Add echo "Working"; to the DisplayError function and comment header("Location: " . $returnlink); and execute resetpassword.php.. Does it return Working?
It does. I have moved session_start into DisplayError in error.php, and have got it working. However I do not understand how. I seriously do not understand what is going on with my code now. @PaulE ~ Also would you mind saying this all again as a solution so that we may discuss in there? And so I can credit you for your help.
|

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.