![](/img/trans.png)
[英]PHP Form POST redirects to 403 error page by LiteSpeed Web Server
[英]Mobile detection via PHP in Wordpress with Litespeed Web Server
我们在发布网站上使用 wordpress,我有一种情况,我需要使用服务器端移动检测来提供一些广告脚本。 Javascript 不是解决方案,因为来自广告服务器的脚本非常复杂。
问题是条件根本不起作用。 桌面被交付给移动设备。
到目前为止,我尝试了 2 个解决方案:
wp_is_mobile() Mobile_Detect.php
它们都在本地工作 - 在移动设备上为 true,在桌面上为 false(使用 Mamp),但在生产服务器中都没有工作。
我尝试从 Litespeed Cache 插件中启用 Mobile Cache,并尝试了他们文档中推荐的其他重写条件。 没有任何工作。
我们还在 WordPress 之外尝试了一个简单的 mobile_detect 实现,同样的问题:桌面交付到移动设备。
我们的服务器是带有 WHM 的 VPS,因此我们具有 root 访问权限。
欢迎任何建议!
谢谢!
你试过这个吗?
function wp_is_mobile() {
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
$is_mobile = false;
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // Many mobile devices (all iPhone, iPad, etc.)
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
$is_mobile = true;
} else {
$is_mobile = false;
}
/**
* Filters whether the request should be treated as coming from a mobile device or not.
*
* @since 4.9.0
*
* @param bool $is_mobile Whether the request is from a mobile device or not.
*/
return apply_filters( 'wp_is_mobile', $is_mobile );
}
学分: https://developer.wordpress.org/reference/functions/wp_is_mobile/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.