MyBB Community Forums

Full Version: Redirected too many times
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am experimenting/ trying to make a file named sso.php in the root folder. And include(require_once) this file on index.php so that when the website loads, the sso.php codes will run as well. But when I entered on the forum, it says  forum.com redirected you too many times . Some code in sso are:

define('IN_MYBB', 1);

require_once './global.php'; 

while (some code here) {
		if (user email is existing){
                    
                    Force user to login!

                    header( "Location: index.php" )
                    header( "Content-Length: 0" );
  	            exit;

                 else{

                header( "Location: member.php?register" ); 
                exit;
                 } 
}
member.php?register => should be member.php?action=register
(2016-03-18, 07:38 AM).m. Wrote: [ -> ]member.php?register => should be member.php?action=register

sorry about that, changed it but still no work.

I think whenever I load the index.php file (which i require_once the sso.php file) it will call the sso file then call the index file again.. Its redirect looping.
You have no checks for the current page.
(2016-03-18, 09:24 AM)nth Wrote: [ -> ]You have no checks for the current page.

sorry, what do you mean by that?
Can you post your code please?
(2016-03-21, 12:47 AM)nth Wrote: [ -> ]Can you post your code please?

$result = $db->query("SELECT * FROM ".TABLE_PREFIX."users");
while ($row = $db->fetch_array($result)) {

	$myybbuser_email = $row['email'];
	$name = $row['username'];
	$the_email = '[email protected]';

		if ($myybbuser_email == $the_email){
			
			$query = $db->simple_select("users", "uid,username,password,salt,loginkey,email,usergroup", "username='$name'", array('limit' => 1));
			$user = $db->fetch_array($query);
		
			my_setcookie('loginattempts', 1);

       		$db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."' AND sid != '".$session->sid."'");
       		
			$newsession = array(
            	"uid" => $user['uid'],
        	);

			$db->update_query("sessions", $newsession, "sid='".$session->sid."'");
			
			$db->update_query("users", array("loginattempts" => 1), "uid='{$user['uid']}'");
			
			// Temporarily set the cookie remember option for the login cookies
			$mybb->user['remember'] = $user['remember'];
		
			my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], null, true);
			my_setcookie("sid", $session->sid, -1, true);
		
			$plugins->run_hooks("member_do_login_end");
			
		
    		header( "Location: index.php" ); 
     		header( "Content-Length: 0" );
			exit; 

 	 	}
		else{
			
		header( "Location: member.php?action=register" ) ; 
    		header ("Content-Length: 0");
			exit;
	 	}
}


This is my code for sso.php file. I required in once in my index.php
Okay, so, what if they are already in index.php? You're just redirecting them back to index.php and it makes a loop. You need to check if the page they are already on is index.php, if it isn't, then redirect them. If it is, don't redirect them or redirect them elsewhere.
(2016-03-21, 12:03 PM)nth Wrote: [ -> ]Okay, so, what if they are already in index.php? You're just redirecting them back to index.php and it makes a loop. You need to check if the page they are already on is index.php, if it isn't, then redirect them. If it is, don't redirect them or redirect them elsewhere.

do you know how?
if(defined('THIS_SCRIPT') && THIS_SCRIPT == 'index.php')
{
	//do not redirect
} else {
	// redirect
}