<?php
/**
* Определение параметров мобильного устройства через яндекс api
* автор: Nc_Soft
* 21.04.10
*/
/*
Дока http://api.yandex.ru/detector/doc/dg/concepts/About.xml
но пример для пхп там на данный момент неверный, вот мой вариант
*/
$headers = array();
$hmask = array(
'profile',
'wap-profile',
'x-wap-profile',
'user-agent',
'x-operamini-phone-ua',
);
foreach ($_SERVER as $key => $value) {
if (strpos($key, "HTTP_") === 0) {
$field = substr($key, 5);
$field = strtolower($field);
$field = str_replace('_', '-', $field);
if (in_array($field, $hmask)) $headers[$field] = $value;
}
}
$ch = curl_init('http://phd.yandex.net/detect?'.http_build_query($headers));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
curl_close($ch);
unset($headers);
echo $res;
/*
про ответы сервера можно почитать тут
http://api.yandex.ru/detector/doc/dg/concepts/detector-response.xml
И, пожалуйста, кэшируйте запросы к апи, не долбите яндекс :)
*/
?>