Link to home
Create AccountLog in
Avatar of Wanda Marston
Wanda MarstonFlag for Canada

asked on

PHP - Page not redirecting properly.

When I try to login to my testing site, I get a message saying that the page is not directing properly. The browser has also come back with the following error message.


I did clear the cookies.


This page isn’t working

www.tXXXXXXXXXXXX.com redirected you too many times.


ERR_TOO_MANY_REDIRECTS


The page isn’t redirecting properly

An error occurred during a connection to www.tXXXXXXX.com

    This problem can sometimes be caused by disabling or refusing to accept cookies.

Open in new window

I do not have my website set up to neither decline or accept cookies. Is this something that I HAVE to do these days. I have sessions on my page but maybe I do not have those set up correctly?

Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Double-check your code that you're not unintentionally creating an infinite loop of redirects.


Add error reporting and logging to see if any specific errors or warnings are being triggered during the redirect process.


Lastly, check if you have any redirects set up in your website's .htaccess file.



ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Wanda Marston

ASKER

Screenshot 2023-06-27 at 8.12.25 AM.pngCouldn't seem to upload any actual mini files so following is the code for the configuration page and then the Login page where I think that the errors might be. Also attached is a screenshot of the latest error that the browser is giving me. 


<?php


//This is the config.inc.php file for the live site June 24, 2023


// This function redirects invalid users.

// It takes two arguments: 

// - The session element to check

// - The destination to where the user will be redirected. 

function redirect_invalid_user($check = 'user_id', $destination = 'index.php', $protocol = 'http://') {

   

   // Check for the session item:

   if (!isset($_SESSION[$check])) {

      $url = $protocol . BASE_URL . $destination; // Define the URL.

      header("Location: index.php");

      exit(); // Quit the script.

   }

   

} // End of redirect_invalid_user() function.


LOGIN.PHP


<?php


// TBR.COM - Live Site - 24 June 2023


//error_reporting(E_ALL);

//ini_set('display_errors', 1);


// Require the configuration before any PHP code as the configuration controls error reporting:

require ('./includes/config.inc.php');

   



      // Query the database:

      $q = "SELECT id, username, pass FROM users WHERE email='$e' AND active IS NULL";

      $r = mysqli_query($db, $q) or trigger_error("Query: $q\n<br>MySQL Error: " . mysqli_error($db));

      

      if (mysqli_num_rows($r) == 1) { // A match was made.


         // Fetch the values:

         list($id, $username, $pass) = mysqli_fetch_array($r, MYSQLI_NUM);

         mysqli_free_result($r);


         // Check the password:

         if (password_verify($p, $pass)) {


            // Store the info in the session:

            $_SESSION['user_id'] = $id;

            $_SESSION['username'] = $username;

      

            mysqli_close($db);

            

            // Redirect the user:

              header('Location: MemberProfileTBR.php');

            exit(); // Quit the script.

            

            } else {

            


<!doctype html>



<div id="description">


<h2>Login</h2>


Your browser must allow cookies in order to log in.<br >


<form action="Login.php" method="post">

<strong>Email Address:</strong> <input type="email" name="email" size="20" maxlength="150">


<a href="ForgotPassword.php"><h2>Forgot Your Password?</h2></a>

    

<strong>Password: Click inside the box to show or hide password.</strong> <input type="password" name="pass" id="pass" value=""  onclick="myFunction()">

    

<button class="button" style="vertical-align:left"><span>Login &rarr;</span></button>

</form>


<script>

function myFunction() {

  var x = document.getElementById( 'pass');

  if (x.type === "password") {

    x.type = "text";

  } else {

    x.type = "password";

  }

}

</script>

 </div> 




// Omit the closing PHP tag to avoid 'headers already sent' errors!


Did you get this solved?

No, Not really. 


I checked one of my other sites that I am developing that was based on the same model and was also having some problems with that. 


SO I checked everything I could, and decided to update some of the pages. MAYBE I will know what went wrong when that is done, but I think that the redirection code and process was outdated.