Jump to content

Too many redirects error in php


gmc1103

Recommended Posts

Hi

 

I'm having a problem with this error

 

This is my code

<?PHP
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("index.php");
    exit;
}

if($fgmembersite->UserId() == 1261){
		 $fgmembersite->RedirectToURL("testes.php");
		 exit;
	}
	
$userid = $fgmembersite->UserId();
?>

And the result is a lot of testes.php until i get that error

 

my chrome debug gives me this

 

  1. Request URL:
  2. Request Headers
    1.  
      Provisional headers are shown
    2. Accept:
      text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    3. User-Agent:
      Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36
 
Any help
Link to comment
https://forums.phpfreaks.com/topic/294500-too-many-redirects-error-in-php/
Share on other sites

Just a suggestion

You may want to send the userid after authentication to $_SESSION and have a script like this on your testes.php

 

http://php.net/manual/en/reserved.variables.session.php

<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
if(!session_id()){session_start();}
require_once("./include/membersite_config.php");
if($_SESSION['userid'] != 1261){die(header('refresh:0; ../index.php', false));} //Do not pass Go, Do not collect $200 if userid is not equal to 1261

//Insert more code

?>
<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{

    $redir_index = "<meta http-equiv='refresh' content='0;index.php'>";
    $fgmembersite->$redir_index();
    exit;
}

if($fgmembersite->UserId() == 1261){
                 $redir_test = "<meta http-equiv'refresh' content='0;testes.php'>";
$fgmembersite->$redir_test();
exit;
}

$userid = $fgmembersite->UserId();
?>

 

Try this

You are redirecting to the same page.

I would remove the:

if($fgmembersite->UserId() == 1261){
         $fgmembersite->RedirectToURL("testes.php");
         exit;
    }

because you don't need to do this since you are already in the file. You can just add your extra code in the same file to do what you want to do. No redirect needed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.