2017-10-22 10 views
0

デバイスを検出するページを作成しています。私はDetect Deviceを検出に使用しています。しかし、私はエラーを取得しています:PHPでデバイスを検出中に未定義のプロパティエラーが発生しました

enter image description here

マイのindex.php

そのエラーを解決する方法
<?php include 'detect.php'; 

if (Detect::isMobile()) { 

} 

// Gets the device type ('Computer', 'Phone' or 'Tablet'). 
echo Detect::deviceType(); 

// Any phone device 
if (Detect::isPhone()) { 

} 

// Any tablet device. 
if (Detect::isTablet()) { 

} 

// Any computer device (desktops or laptops). 
if (Detect::isComputer()) { 

} 

// Get the IP address of the device. 
echo Detect::ip(); 

// Get the ID address host name of the device. 
echo Detect::ipHostname(); 

// Get the IP address organisation of the device. 
echo Detect::ipOrg(); 

// Get the country the IP address is in (IP address location inaccurate). 
// (JS function available which uses GPS) 
echo Detect::ipCountry(); 

// Get the name & version of operating system. 
echo Detect::os(); 

// Get the name & version of browser. 
echo Detect::browser(); 

// Get the brand of device (only works with mobile devices otherwise return null). 
echo Detect::brand(); 

// Check for a specific platform with the help of the magic methods: 
if (Detect::isiOS()) { 

} 

if (Detect::isAndroidOS()) { 

} 
?> 
<head> 
    ... 
    <script type="text/javascript" src="path_to/detect.js"></script> 
    ... 
</head> 
<script> 
// Get screen width in pixels. 
detect.screenWidth(); 

// Get screen height in pixels. 
detect.screenHeight(); 

// Get viewport (browser window minus any toolbars etc) width in pixels. 
detect.viewportWidth(); 

// Get viewport (browser window minus any toolbars etc) height in pixels. 
detect.viewportHeight(); 

// Get latitude from GPS & update html conent of ID element passed. 
// Null, if GPS unavailable. 
detect.latitude("latitude"); 

// Get longitude from GPS & update html conent of ID element passed. 
// Null, if GPS unavailable. 
detect.longitude("longitude"); 

// Get address from GPS & update html conent of ID element passed. 
// Null, if GPS unavailable. 
detect.address("address"); 
</script> 

デバイスを検出する機能を提供する他のWebサイトはありますか?

私はデバイスを検出するページを作成しています。私はDetect Deviceを検出に使用しています。しかし、私はエラーが発生しています:See Here

+0

これはエラーではありません。しかしただの通知!残りのコードは完全に動作し、この警告を抑制するためにdetect.phpファイルをチェックします。通知に見られる行番号248。 – Shan

答えて

0

この問題は、コードによってではなく、DeviceDetectクラスのコードのバグによって引き起こされます。それはhttp://ipinfo.io/jsonを呼び出します。このコードでは、 "hostname"という名前のプロパティは常に存在すると想定していますが、明らかにそうではありません(エラーに基づいています)。

http://mobiledetect.net/バリアントではなく、このDeviceDetectクラスを使用する理由はありますか?あなたはDeviceDetectクラスを使用して保存しておきたい場合は

、あなたはこれで246行を置き換えることによって、バグを修正することができます:

self::$ipInfo = json_decode(file_get_contents('http://ipinfo.io' . self::$ipUrl . '/json')); 
 
self::$ipAddress = !empty(self::$ipInfo->ip) ? self::$ipInfo->ip : ''; 
 
self::$ipInfoHostname = !empty(self::$ipInfo->hostname) ? self::$ipInfo->hostname : ''; 
 
self::$ipInfoOrg = !empty(self::$ipInfo->org) ? self::$ipInfo->org : ''; 
 
self::$ipInfoCountry = !empty(self::$ipInfo->country) ? self::$ipInfo->country : '';

+0

ログインしたユーザーに電子メールを送信し、ユーザーがクロムを使用してコンピュータからログインしたことを伝えることができるようにしたい。 –

+0

理由。しかし、私の意見では、DeviceDetectクラスは最高のものではありません。 「ハッピー・パス」のみをチェックし、何かが失敗したかどうかをチェックしません。また、一部のユーザー情報を検出するために、一部のオンラインサービスに追加のHTTP要求を行います。私の意見では、http://mobiledetect.net/からのクラスは、追加のhttp呼び出しなしで必要なものを正確に与えるべきです。 – 58k723f1

+0

http://mobiledetect.netに電話かコンピュータかブラウザかを示すだけです。しかし、ブランド、IPアドレス、場所が必要です –

関連する問題