Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error: Cannot redeclare class Mobile_Detect #622

Closed
Gregory9111 opened this issue Jan 9, 2017 · 7 comments
Closed

PHP Fatal error: Cannot redeclare class Mobile_Detect #622

Gregory9111 opened this issue Jan 9, 2017 · 7 comments

Comments

@Gregory9111
Copy link

Hello,

I`m getting following error :

[09-Jan-2017 06:53:42 UTC] PHP Fatal error: Cannot redeclare class Mobile_Detect in /var/www/vhosts/website.com/httpdocs/libs/MobileDetect/Mobile_Detect.php on line 29

My version is @Version 2.8.24

The issue is random for me and not very frequent - can you resolve ?

tnx
Grzegorz

@Gregory9111
Copy link
Author

Hey all - any idea about that issue ?

@djarrin
Copy link

djarrin commented Jan 11, 2017

Did you edit the plugin at all or have a class declaration of Mobile_Detect anywhere else on your site?

@fmonts
Copy link

fmonts commented Jan 11, 2017

This is not an issue, you included the Mobile_Detect.php twice.

You can use include_once instead of include (or require_once instead of require), for example

@Gregory9111
Copy link
Author

Gregory9111 commented Jan 11, 2017

I use it like this

/httpdcs/fun.php

` function isMobile()
{

	if( !isset( $_SESSION['ips_mobile'] ) )
	{
		require( LIBS_PATH . '/MobileDetect/Mobile_Detect.php' );
		$detect = new Mobile_Detect;
		$mobile_detect = $detect->isMobile();
		$_SESSION['ips_mobile'] = $mobile_detect;
	}
	
	return $_SESSION['ips_mobile'];
}`

and for mobile same code in structure
/httpdcs/m/fun.php

How it should looks like to work properly ?

That issue I described is very rare - normally website detection works very good

@u-mulder
Copy link
Contributor

When you call your isMobile function more than once, you include Mobile_Detect.php more than once. Replace require with require_once.

@leegee
Copy link

leegee commented Mar 31, 2017

Used Wordpress to install this, got the same error. Switching to another plugin, but thought you should know.

@serbanghita
Copy link
Owner

Thank you @u-mulder and everyone for the assist on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants