Skip to content
Advertisement

PHP Disabling registration from any mobile device, only allow user registration from a Desktop

I usually post code but this is a slightly different case.

I would like to disable my registration page from being used on a mobile device.

EG: icloud.com’s login is not accessible from any mobile device.

So what I came to conclude is that I might need to catch the users user-agent and if its a mobile platform redirect it to a disabled page?

I’m not really sure as to how to go about this, meaning could this be disabled via apache2 or a simple user-agent grabber using PHP or JS?

Advertisement

Answer

You can use a php class called http://mobiledetect.net/

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;

// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {

}

// Any tablet device.
if( $detect->isTablet() ){

}

// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){

}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement