• I wasn’t able to get this to work off the bat. I realized that you are redirecting someone on the ‘init’ action, which is before you would ever get to the page where the cookie was being set to stop the redirect, so it would just never get to the point where that cookie was set. I had to update the plugin functions.php to this:

    //add_action('init', 'pmr_mobile_redirect');
    
    	function redirect_without_infinite_loop(){
    		// --- Added by Brian because if we don't do this it will endlessly loop
    		if(!is_page('mobile')){
    			pmr_mobile_redirect();
    		}
    	}
    	add_action('get_header','redirect_without_infinite_loop');
    
    	function pmr_mobile_redirect(){
    
    		global $pmr_options;
    
    		if ($pmr_options['enabled'] == true)
    		{
    			$detect = new Mobile_Detect();
    
    			if ($detect->isMobile() && isset($_COOKIE[$pmr_options['mobile_cookie']]))
    			{
    				$detect = "false";
    			}
    			elseif ($detect->isTablet() && $pmr_options['tablet'] == true)
    			{
    				$detect = "false";
    			}
    			elseif ($detect->isMobile())
    			{
    				header('Location: https://' . $pmr_options['mobile_url']);
    				exit;
    			}
    		}
    	}

    ‘mobile’ is the slug of my mobile page, other users would have to update their code to correctly identify their mobile page. This way, if users arethere it won’t keep redirecting them. I’m surprised in your code there is not already something to prevent this behavior. Is there any way I can get this to work without my adjustments to your code?

    https://www.ads-software.com/plugins/php-mobile-redirect/

  • The topic ‘Endless loop redirect’ is closed to new replies.