Im currently playing around with browser detection mainly for statistics from the site and to better design the site in future. No ive been told the best way to go about this is to use the following code which shows all the browser info in an array if all my ini files are in place (which they are)
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "$brw = <b>$key:</b> $value<br>\n";
}
return $str;
}
echo "$HTTP_USER_AGENT<hr>\n";
$browser = get_browser();
echo list_array ((array) $browser);
The then displays this
browser_name_regex: �^mozilla/5\.0 \(.*windows nt 6\.2.*wow64.*\) applewebkit/.* \ (khtml, like gecko\).*chrome/28\..*safari/.*$�
= browser_name_pattern: Mozilla/5.0 (*Windows NT 6.2*WOW64*) AppleWebKit/* (KHTML, like Gecko)*Chrome/28.*Safari/*
= parent: Chrome 28.0
= platform: Win8
= platform_version: 6.2
= win32:
= win64: 1
= comment: Chrome 28.0
= browser: Chrome
= version: 28.0
= majorver: 28
= minorver: 0
= frames: 1
= iframes: 1
= tables: 1
= cookies: 1
= javascript: 1
= javaapplets: 1
= cssversion: 3
= alpha:
= beta:
= win16:
= backgroundsounds:
= vbscript:
= activexcontrols:
= ismobiledevice:
= issyndicationreader:
= crawler:
= aolversion: 0
Now heres were the problem lies all detect browser php plugings or download are overly complicated all im looking to do i seperate iphones ipads android blackberry apple and some of the most basic pieces of information. How can I turn this array into variables that can be used later. for example if i can grab the 2nd 3rd n 4th in the array i will have all the information i want as accurate as i need it all otherways and i seem to get problems with iphones showing as just a mobile device and what not Ive already tried for example
if (preg_match('/windows nt 6.2/i', $u_agent)) {
$platform = 'Windows 8';
}
and
$blackberry = strpos(&ua, 'Android') ? true : false;
and looked at
http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php.html
http://www.phpjabbers.com/php-snippet/detect-browser-php.php
http://www.killersites.com/community/index.php?/topic/2562-php-to-detect-browser-and-operating-system/
First of all, you should use foreach() instead of each + list. See http://www.php.net/manual/fr/function.each.php#63805
Second, you're casting the result of get_browser as an array for your list_array function when you do (array) $browser, that's why it works and why it doesn't create a fatal error.
If you want to use the result of get_browser as an array, you should however use the built in option to do so, ie :
$b = get_browser(null, true);
The second option here tells get_browser to return an array instead of an object, this should solve your problem of trying to use a class as an array.
You will then be able to use :
echo $b['browser'];
The default return type for get_browser beeing an object, you would have to use
$b = get_browser();
echo $b->browser;
if you wanted the same result.
Try reading the php manual http://php.net/manual/en/function.get-browser.php to get a better understanding of the functions you're using. You will find useful code in the comments aswell.
Finally, as you've been told, you should use an existing API for statistics.
Good luck with your coding.
Related
This question already has answers here:
Facebook API: Get fans of / people who like a page
(8 answers)
Closed 5 years ago.
I am working with codeigniter.
I want to get user list who likes facebook page,in page currently 675 likes but,from below code it shows me 6 likes only ,I am not sure this is correct way or not.
public function fetch_fb_fans($fanpage_name="pagename", $no_of_retries = 10, $pause = 500000 /* 500ms */){
$ret = array();
// prepare real like user agent and accept headers
$context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-encoding: gzip, deflate, sdch\r\nAccept-language: en-US,en;q=0.8,pl;q=0.6\r\n')));
// get page id from facebook html og tags for mobile apps
$fanpage_html = file_get_contents('https://www.facebook.com/' . $fanpage_name, false, $context);
if(!preg_match('{fb://page/(\d+)}', $fanpage_html, $id_matches)){
// invalid fanpage name
return $ret;
}
$url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=pageid';
for($a = 0; $a < $no_of_retries; $a++){
$like_html = file_get_contents($url, false, $context);
preg_match_all('{href="https?://www\.facebook\.com/([a-zA-Z0-9\._-]+)" data-jsid="anchor" target="_blank"}', $like_html, $matches);
if(empty($matches[1])){
// failed to fetch any fans - convert returning array, cause it might be not empty
return array_keys($ret);
}else{
// merge profiles as array keys so they will stay unique
$ret = array_merge($ret, array_flip($matches[1]));
}
// don't get banned as flooder
usleep($pause);
}
echo"<pre>";print_r($ret);die;
}
can any one help me to get required result?
This is the documentation of the plugin.
https://developers.facebook.com/docs/plugins/page-plugin
The connections param doesn't is accepted and no take effects.
I want to get the name of all keys for memcached, but Memcached::getAllKeys method always return false.
use contos 6.5 + memcached 1.4.31 + php-memcached-2.2.0 PECL
It looks like newer versions of memcached don't like nor support the getAllKeys method.
However it looks like someone made it work by setting
Memcached::OPT_BINARY_PROTOCOL = false
If it does not work I think you have to fall back to 1.4.23 version or install REDIS :P
I had the same problem on my live server. I was preparing a test to show the techs there how to replicate my problem:
$m = new Memcached();
$m->addServer(MEMCACHED_SERVER, MEMCACHED_PORT);
echo "added ". MEMCACHED_SERVER. ":". MEMCACHED_PORT. PHP_EOL;
$keys = [];
$stop = 100;
foreach( $m->getAllKeys() as $k){
array_push( $keys, $k );
if( --$stop == 0 ) break;
}
var_dump( $keys );
this would return 100 keys on my local R&D server, but an empty list on the live server. To show them there was definitely something in there I echoed a dump of a key in there that I knew for sure was there:
var_dump( $m->get( "cache:pool:70:230" ));
that line showed there was a key, but it also made getAllKeys to return a list of 100 entries more! I still believe this is a bug, but there is a workaround.
Edit: Turns out any redundant call before getallkeys fixes this: $m->getVersion(); would also make getAllKeys works
I am trying to integrate First Data e4 Gateway using PHP. I downloaded the VinceG/php-first-data-api PHP First Data Service API class. The code comes with some examples.
I have my Terminal ID (API_LOGIN) and Password (32 character string).
What confuses me is that when I use one of the examples, I don't know how to tell the class that I want to use the demo url, not the production url.
The class comes with two constants:
const LIVE_API_URL = 'https://api.globalgatewaye4.firstdata.com/transaction/';
const TEST_API_URL = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/';
In the First Data console, when I generated my password, it said to use the v12 api, /transaction/v12, so I changed the protected $apiVersion = 'v12';
All I want to do is write my first development transaction using First Data e4. I have yet to get any kind of response. Obviously I need a lot of hand holding to get started.
When I set up a website to use BalancedPayments, they have a support forum that's pretty good, and I was able to get that running fairly quickly. First Data has a lot of documentation, but for some reason not much of it has good PHP examples.
My hope is that some expert has already mastered the VinceG/php-first-data-api, and can help me write one script that works.
Here's the pre-auth code I'm using, that invokes the FirstData class:
// Pre Auth Transaction Type
define("API_LOGIN", "B123456-01");
define("API_KEY", "xxxxxxxxxxyyyyyyyyyyyyzzzzzzzzzz");
$data = array();
$data['type'] = "00";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vance";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33333";
$data['cvv'] = "123";
$data['address'] = "1111 OCEAN BLVD MIAMI FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
// Charge
$firstData->setTransactionType(FirstData::TRAN_PREAUTH);
$firstData->setCreditCardType($data['type'])
->setCreditCardNumber($data['number'])
->setCreditCardName($data['name'])
->setCreditCardExpiration($data['exp'])
->setAmount($data['amount'])
->setReferenceNumber($orderId);
if($data['zip']) {
$firstData->setCreditCardZipCode($data['zip']);
}
if($data['cvv']) {
$firstData->setCreditCardVerification($data['cvv']);
}
if($data['address']) {
$firstData->setCreditCardAddress($data['address']);
}
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
My number one problem was that I had not created (applied for, with instant approval) a
demo account on First Data. I didn't realize this was a separate thing on First Data. On Balanced Payments, for instance, you have one account, and you can run your script on a test url with test values.
From the Administration panel, click "Terminals", then your Gateway number on the ECOMM row (will look something like AH1234-03), then you have to click "Generate" on password save it to your personal notes), then click UPDATE.
Now replace your parameter values in your test scripts. I use a variable assignment block that looks something like this:
define("API_LOGIN", "AH1234-05"); //fake
define("API_KEY", "44p7797xxx790098z1z2n6f270ys1z0x"); //fake
$data = array();
$data['type'] = "03";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vancce";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33320";
$data['cvv'] = "123";
$data['address'] = "1234 N OCEAN BLVD MIAMI BEACH FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
at the end of the VinceG test scripts, I output my gateway response with a print_r, like this:
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
echo "<pre>";
print_r($firstData);
I'm currently developing an app in a IGB (In-Game-Browser) for an Online MMO. For third party development the browser sends HTTP headers with in game information such as Locations, Item ID's, Items Type ID's, etc,.
It's a small script I've been using to practice with. This script works on my local server and like everyone else who's posted on this issue it does not work on my web server. I have come to the conclusion that this is due to Apache not being installed as a module. I spoke with my hosting provider. They said they could not tell me anything other than I need to find an alternative to "apache_request_headers". I've looked over all the previously posted issues on this topic on this site and I'm unable to see how it all fits together. How to use the examples on here to accomplish my end result. Like this [question]: Call to undefined function apache_request_headers()
My code:
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}
?>
My error:
Fatal error: Call to undefined function apache_request_headers() in /home/ncgotggb/public_html/ezalternatives.com/index.php on line 2
I have been learning as I go this year and it's been self taught and at a fast pace so I'm still newbish to alot of these concepts. At this point tho I have no choice I'm heavily committed and need to complete it. When displaying your answer It would be greatly appreciated if you showed your solution in complete form.
It sounds like your local server is running Apache and your remote server is not, as this function only works with Apache (unless the server is running PHP 5.4.0, then it also works under FastCGI.
On the PHP Manual page for this function, one of the commenters included a replacement function that will be declared only if the built-in one doesn't exist. I haven't tested this, but I've seen the same function posted elsewhere.
if( !function_exists('apache_request_headers') ) {
function apache_request_headers() {
$arh = array();
$rx_http = '/\AHTTP_/';
foreach($_SERVER as $key => $val) {
if( preg_match($rx_http, $key) ) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
foreach($rx_matches as $ak_key => $ak_val) {
$rx_matches[$ak_key] = ucfirst($ak_val);
}
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return( $arh );
}
}
I found that my site in ISP Config was set to have PHP as 'Fast-CGI' - changing this to 'MOD-PHP' fixed things nicely.
I wanted to know, is there any way from PHP/javascript to get current client OS language. I tried to use $_SERVER["HTTP_ACCEPT_LANGUAGE"] but sometimes it get the wrong language.
For example in Google Chrome:
My OS: Windows 7
Language: English
Using $_SERVER["HTTP_ACCEPT_LANGUAGE"] I got this result:
HTTP_ACCEPT_LANGUAGE: zh,en-US;q=0.8,en;q=0.6
It said "zh" is my primary language.
Is there any other way to get client OS language? Because that's what I wanted, not the browser language setting. Thanks
try this function
function getUserLanguage() {
$langs = array();
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
// break up string into pieces (languages and q factors)
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
$_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
if (count($lang_parse[1])) {
// create a list like â??enâ?? => 0.8
$langs = array_combine($lang_parse[1], $lang_parse[4]);
// set default to 1 for any without q factor
foreach ($langs as $lang => $val) {
if ($val === '') $langs[$lang] = 1;
}
// sort list based on value
arsort($langs, SORT_NUMERIC);
}
}
//extract most important (first)
foreach ($langs as $lang => $val) { break; }
//if complex language simplify it
if (stristr($lang,"-")) {$tmp = explode("-",$lang); $lang = $tmp[0]; }
return $lang;
}
Send it via javascript on IE?
navigator.browserLanguage: browser language
navigator.systemLanguage: Windows system language
navigator.userLanguage: Windows user-specific language
Thanks to: Is there anyway to detect OS language using javascript?
That's the only way besides the one you've mentioned to get the language of the client OS, PHP is run by the server and nothing else.
Build a PHP sorting function.
HTTP_ACCEPT_LANGUAGE: zh,en-US;q=0.8,en;q=0.6
zh and en-US share the same q= value, meaning that you can sort on the highest language value and default to en-US if the quality is the same on two languages.
Just noticed that #Quentin mentioned this in the comment section a minute before my edit, well done sir!
Mockup:
$languages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$default = 'en-US';
/*
* magic split and structure the language into a array sorted by quality
*
* $languages_sorted_by_quality = array(0.8 => ('zh', 'en-US'));
*/
$top_languages = max($languages_sorted_by_quality);
if (isset($top_languages[$default])) {
$language = $default;
else
$language = $top_languages[0];
have your tried http_negotiate_language