Title: Endless loop redirect
Last modified: August 21, 2016

---

# Endless loop redirect

 *  [BVBAccelerate](https://wordpress.org/support/users/bvbaccelerate/)
 * (@bvbaccelerate)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/endless-loop-redirect/)
 * 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: http://' . $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?
 * [http://wordpress.org/plugins/php-mobile-redirect/](http://wordpress.org/plugins/php-mobile-redirect/)

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

 * ![](https://s.w.org/plugins/geopattern-icon/php-mobile-redirect_949495.svg)
 * [PHP Mobile Redirect](https://wordpress.org/plugins/php-mobile-redirect/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/php-mobile-redirect/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/php-mobile-redirect/)
 * [Active Topics](https://wordpress.org/support/plugin/php-mobile-redirect/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/php-mobile-redirect/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/php-mobile-redirect/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [BVBAccelerate](https://wordpress.org/support/users/bvbaccelerate/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/endless-loop-redirect/)
 * Status: not resolved