我阅读了很多文章,并寻找检测移动设备的解决方案。实际上遇到了https://github.com/serbanghita/mobile-detect,但它是一个非常庞大的php类。
我其实想要一个非常简单的解决方案。我想确定用户的浏览器是Mobile / iPad / etc还是桌面。所以我想要这样的东西:
<?php
require('detector.php');
if(isMobile() === true)
{
header('mobile.php');
exit();
}
else
{
header('desktop.php');
exit();
}
&GT;
我需要一个非常简单的解决方案,我可以放置到任何页面而无需安装composer或任何php框架。
这实际上怎么可能?
答案 0 :(得分:6)
您是否真的尝试过使用您发现的项目?我要说服务器端移动检测是一项艰巨的任务,需要进行大量细节检查以确保正确的结果。
使用这个课程非常简单。从示例目录:
require_once '../Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
现在你有一个带有三个值之一的变量:“tablet”,“phone”或“computer”,你可以对此做出反应。
请注意,即使您能够在没有Composer的情况下使用此库,它也会定期更新(如“每月一次”),因为新设备已上市并需要检测。您必须在某个时候更新此库。使用Composer使这很容易。
答案 1 :(得分:1)
您可以使用
重定向链接
在控制器中,您可以查看
Public Class Form1
Dim TestValue As Single = 0
Dim TestAnim As Animating
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TestAnim = New Animating(100, TestValue, 1, AddressOf Me.Invalidate)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TestAnim.start()
End Sub
Private Sub Form1_Invalidated(sender As Object, e As InvalidateEventArgs) Handles Me.Invalidated
Debug.WriteLine(TestValue)
End Sub
End Class
Public Class Animating
Dim _to, _value, _stepping As Single
Public Delegate Sub Proc()
Dim procedure As Proc
Public Delegate Sub Resulting(ByRef V2 As Single)
Dim procedures As Resulting
Sub New(ByVal Vto As Single, ByRef value As Single, ByVal stepping As Single, ByRef obj As Proc)
_to = Vto
_value = value
_stepping = stepping
procedure = obj
procedures = New Resulting(Sub()
calc(value)
End Sub)
End Sub
Sub start()
Threading.ThreadPool.QueueUserWorkItem(New Threading.WaitCallback(Sub()
calc(_value)
End Sub))
End Sub
Sub calc(ByRef value As Single)
Threading.Thread.Sleep(50)
value += _stepping
procedures(value)
procedure.Invoke
If value >= _to Then Exit Sub
calc(value)
End Sub
End Class
答案 2 :(得分:0)
我发现这个简单的行非常可靠且易于实现..无需添加一个额外的类。
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
echo "running on mobile";
}