HOME > > > > >

動作サンプル

処理の内容を把握できてないので間違ってる可能性大です。

&singleton($in_userAgent = null, $in_detect = null)

インスタンスを取得。singletonパターンが適用されてるのでnewしちゃダメ。

PHP

  1. <?php
  2. $obj_A =& Net_UserAgent_Detect::singleton();
  3. $obj_B =& Net_UserAgent_Detect::singleton();
  4.  
  5. if ($obj_A == $obj_B) {
  6.     echo "YES";
  7. }
  8. ?>

実行結果

YES

getBrowserString()

ブラウザ名を取得する

PHP

  1. <?php
  2. echo Net_UserAgent_Detect::getBrowserString()
  3. ?>

実行結果

mozilla

Net_UserAgent_Detect::isIE()

ブラウザがIEかどうかを判定する。

PHP

  1. <?php
  2. var_dump(Net_UserAgent_Detect::isIE());
  3. ?>

実行結果

bool(false)

Net_UserAgent_Detect::isNavigator()

ブラウザがNetscape Navigatorかどうかを判定する。

PHP

  1. <?php
  2. var_dump(Net_UserAgent_Detect::isNavigator());
  3. ?>

実行結果

bool(false)

Net_UserAgent_Detect::isNetscape()

ブラウザがNetscape か Mozillaかどうかを判定する。

PHP

  1. <?php
  2. var_dump(Net_UserAgent_Detect::isNetscape());
  3. ?>

実行結果

bool(false)

Net_UserAgent_Detect::isOS($in_match)

OSが$in_matchの場合true

PHP

  1. <?php
  2. $os = array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'wince', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd');
  3.  
  4. foreach ($os as $value) {
  5.     echo $value . ' : ' . (Net_UserAgent_Detect::isOS($value) ? 'YES' : 'NO') . '<br />';
  6. }
  7. ?>

実行結果

win : NO
win95 : NO
win16 : NO
win31 : NO
win9x : NO
win98 : NO
wince : NO
winme : NO
win2k : NO
winxp : NO
winnt : NO
win2003 : NO
os2 : NO
mac : NO
mac68k : NO
macppc : NO
linux : NO
unix : NO
vms : NO
sun : NO
sun4 : NO
sun5 : NO
suni86 : NO
irix : NO
irix5 : NO
irix6 : NO
hpux : NO
hpux9 : NO
hpux10 : NO
aix : NO
aix1 : NO
aix2 : NO
aix3 : NO
aix4 : NO
sco : NO
unixware : NO
mpras : NO
reliant : NO
dec : NO
sinix : NO
freebsd : NO
bsd : NO

Net_UserAgent_Detect::getOS($in_expectList)

うーんいまいち用途不明。

PHP

  1. <?php
  2. $os = array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'wince', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd');
  3. var_dump(Net_UserAgent_Detect::getOS($os));
  4. ?>

実行結果

NULL

Net_UserAgent_Detect::getOSString()

OSを返す。

PHP

  1. <?php
  2. // コード
  3. var_dump(Net_UserAgent_Detect::getOSString());
  4. ?>

実行結果

string(7) "Unknown"

Net_UserAgent_Detect::hasQuirk($in_quirk)

引数の機能が利用できるかどうかを判定(たぶん。。。)引数が何の機能を表してるかも不明・・・だれか教えてぇ〜

PHP

  1. <?php
  2. $quirks = array(
  3.     'must_cache_forms'         => 'must_cache_forms',
  4.     'popups_disabled'          => 'ポップアップブロッカー?',
  5.     'empty_file_input_value'   => 'empty_file_input_value',
  6.     'cache_ssl_downloads'      => 'cache_ssl_downloads',
  7.     'scrollbar_in_way'         => 'scrollbar_in_way',
  8.     'break_disposition_header' => 'break_disposition_header',
  9.     'nested_table_render_bug'  => 'nested_table_render_bug'
  10. );
  11.  
  12. foreach ($quirks as $key => $value) {
  13.         echo $key . '[$value]: '  . (Net_UserAgent_Detect::hasQuirk($key) ? 'YES' : 'NO') . '<br />';
  14.  
  15. }
  16. ?>

実行結果

must_cache_forms[must_cache_forms]: NO
popups_disabled[ポップアップブロッカー?]: NO
empty_file_input_value[empty_file_input_value]: NO
cache_ssl_downloads[cache_ssl_downloads]: NO
scrollbar_in_way[scrollbar_in_way]: NO
break_disposition_header[break_disposition_header]: NO
nested_table_render_bug[nested_table_render_bug]: NO

Net_UserAgent_Detect::getQuirk($in_quirk)

Net_UserAgent_Detect::setFeature($in_feature, $in_hasFeature = true)

Net_UserAgent_Detect::hasFeature($in_feature)

Net_UserAgent_Detect::getFeature($in_feature)

Net_UserAgent_Detect::getAcceptType($in_expectList, $in_type)

Net_UserAgent_Detect::setAcceptType($in_values, $in_type)

Net_UserAgent_Detect::hasAcceptType($in_value, $in_type)

Net_UserAgent_Detect::getUserAgent()

名前のとおりUserAgentを取得する

PHP

  1. <?php
  2. var_dump(Net_UserAgent_Detect::getUserAgent());
  3. ?>

実行結果

string(103) "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"