How to detect dolphin browser in php? - php

How to detect dolphin browser in php? Unfortunatly I don't have android, so I can't check the dolphin browser's user agent.
thanks in advance,

The user agent contains "Dolfin/2.0".

On my version of Dolphin, 8.8.2 - running on a Samsung Galaxy Note, there is no particular user agent and 'desktop' is set. The user-agent is set by tapping on More -> Settings -> User Agent. I am then able to change the user agent to any of the following:
Android
Desktop, which identifies as: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16
iPhone
iPad
Custom (I guess you could set a custom user-agent such as 'dolfin' if you want).
So if you're trying to deliver content specific to the Dolphin browser in PHP you could test if 'mobi' or 'Android' is present in the user agent. If you're trying to detect that the exact browser being used is Dolphin then that will be tricky unless your client device's custom user-agent is set.

You can check the User Agent
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'dolphin') !== false) {
echo 'Your UA is Dolphin';
}
You can do a more accurate check if you know the exact User Agent, but I assumed that if it contains the word dolphin is accurate enough.

Related

Tracking visits from LinkedIn

I use LinkedIn and other Social Media to promote certain blog content on my Website. My website is on Wordpress and I therefore wrote a Plugin that created a widget for displaying the visit source. Once I have this source, I can store this on a table and can view the number of visits from each Social Media channel to test the effectiveness of the post.
The problem is that while I can identify click throughs from Facebook, Twitter, G+ etc. with no problem, I do not get any referer information from LinkedIn.
I use the read the information as follows:
//Get the referer from Wordpress
$ref_raw = wp_get_raw_referer();
echo '<li>RAW: '.( strlen($ref_raw)? $ref_raw: 'None' ).'</li>';
//Get the IP from the server to check
$ref_srv = $_SERVER['HTTP_REFERER'];
echo '<li>PHP: '.( strlen($ref_srv)? $ref_srv: 'None' ).'</li>';
//Get other information
$ip = strlen($_SERVER["HTTP_X_REAL_IP"])? $_SERVER["HTTP_X_REAL_IP"]: $_SERVER['REMOTE_ADDR'];
echo '<li>REFERRER IP: '.( strlen($ip)? $ip: 'None' ).'</li>';
$agent = isset($_SERVER['HTTP_USER_AGENT'])&& strlen($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT']: '';
echo '<li>USER AGENT: '.( strlen($agent)? $agent: 'None' ).'</li>';
echo '<li>URI: '.$_SERVER['REQUEST_URI'].'</li>';
The output from this code when a visit originated from Facebook is as follows:
RAW: https://www.facebook.com/ PHP: https://www.facebook.com/
REFERRER IP: 89.127.12.32
USER AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 REFERRAL
URI: /how-speed-affects-your-website/?fbclid=I123C-as
However, a visit from LinkedIn looks like this:
RAW: None
PHP: None
REFERRER IP: 89.127.12.32
USER AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
REFERRAL TYPE: external
URI: /how-speed-affects-your-website/
Any ideas why there is no referer data being transferred from LinkedIn? or any thoughts on how I can observe visits from LinkedIn by any other means?
Is your own site using HTTPS? And do those links the users follow use HTTPS URLs?
If not, you will simply not get a referrer from LinkedIn in modern browsers, due to Referrer-Policy.
no-referrer-when-downgrade (default)
This is the user agent's default behavior if no policy is specified. The URL is sent as a referrer when the protocol security level stays the same (HTTP→HTTP, HTTPS→HTTPS), but isn't sent to a less secure destination (HTTPS→HTTP).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy#Directives:
LinkedIn doesn’t actively specify a Referrer-Policy as far as I can see, so this fallback value will be used automatically.
So if your site doesn’t support HTTPS, or the links go to the HTTP version first, the browser is forbidden from sending you this info.
or any thoughts on how I can observe visits from LinkedIn by any other means?
Check if they append any specific, uniquely named tracking parameters to outgoing links, like Facebook does with the ?fbclid=I123C-as. Then you could take the existence of that parameter as an indicator that the user most likely followed a link from LinkedIn to your site.

Chrome mobile loads PHP twice?

I'm having a issue where chrome mobile will load the page once, and the load the page again a second later. This is only visible in the server logs. This wouldn't be a problem normally, however I'm using the loaded page to +1 to a MySQL database via a query. So when someone on mobile with chrome visits the page instead of +1 I get +2. Which is problematic.
Server logs:
141.101.98.206 - - [28/Sep/2015:16:18:12 +0100] "GET /vfm-admin/vfm-downloader.php?q=***=&h=***&sh=***&t=***&n=***HTTP/1.1" 200 483 "https://new.***.net/?dl=***" "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LMY48P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2519.0 Mobile Safari/537.36"
141.101.98.206 - - [28/Sep/2015:16:18:13 +0100] "GET /vfm-admin/vfm-downloader.php?q=***=&h=***&sh=***&t=***&n=***HTTP/1.1" 200 144 "https://new.***.net/?dl=***" "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LMY48P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2519.0 Mobile Safari/537.36"
I found this online: https://code.google.com/p/chromium/issues/detail?id=64810
but after implementing everything suggested there the issues still persists, but only on mobile.
I tried to hack my way around the issue by using sessions, but since the script also serves a file to download it just downloads the if session error message as a file, see:
if(isset($_SESSION['user']))
{
echo "Session error, if issue persists please clear your cache</br>";
echo "Back to download</br>";
exit();
}
else
{
//download function
}
Update 1:
As per suggestions I replaced the error echo with the download headers, this works fine on mobile. However if the if statement is then tripped on desktop it endlessly loads with no errors on either end.
if(isset($_SESSION['user']))
{
$headers = $downloader->getHeaders($getfile);
$downloader->aDownload(
$headers['file'],
$headers['filename'],
$headers['file_size']
);
exit();
}
else
{
// download function
}
Chrome & Safari will "prefetch" some pages to accelerate the load time of your navigation.
You can prevent it by detecting the specifics headers : X-Purpose: preview & X-moz: prefetch.
As it has been said in comments, here you can find a lot of cases of such behavior and their solutions.
To find out the place in code which caused this problem, you may open Chrome's Developer Tools, set mobile mode, open Network tab, and filter all the requests by entering "vfm-admin/vfm-downloader.php" into the Filter textfiled.
If you see the same request twice, you will be able to see in the Initiator column the JS or CSS file, which is responsible for such behavior.

How do i get what the name of the device im using with s.server="" ? SiteCatalyst?

I am sending page name and page information to SiteCatalyst.
I need to send the name of the device the visitor is using.
Could someone help me out
s.pageName="<?php the_title();?> (<?php the_ID(); ?>)"
s.server=""
s.channel="Mobilwebben"
My question is what variable do I need to send s.server"" with so i could get the device name?
For this you can use $_SERVER['HTTP_USER_AGENT'] Quote from PHP.net:
Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent.
You may also use this free function to read the user agent using PHP:
Detect Mobile Browsers
I hope this helps.

Reliable way to detect Chrome on Mac in PHP?

As the title says, is there a reliable way to detect whether a user is visiting my page using Chrome on Mac using PHP?
I have a bug that only displays when using Chrome on Mac, and until I get it sorted out I would like to have a popup to recommend the users to use a different browser.
Use $_SERVER['HTTP_USER_AGENT'] to find the users' user agent and a function to check if this is within the string.
//The following will find out whether the user is using a Mac, obviously you can change this by echoing the user agent to find out what you need to search for.
$browser = strpos($_SERVER['HTTP_USER_AGENT'], "Chrome");
$os = strpos($_SERVER['HTTP_USER_AGENT'], "Macintosh; Intel Mac OS X");
if($browser !== false && $os !== false) {
//do stuff if on a mac with Chrome
}
This will work with any type of Mac OS X software and any version of Chrome. If you want to narrow your results down further, you can just use:
if($_SERVER['HTTP_USER_AGENT'] == "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11" ) {
//do stuff here
}
It would be better if you posted the code you're having issues with rather than creating a hacky fix.
However, you can use $_SERVER['HTTP_USER_AGENT'] to check the users browser/OS.
To aid, you would expect something like Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 from a Mac user on Chrome.
Note
The user agent isn't always set so use isset first to avoid notices appearing.
I know you're looking for the PHP solution to find the browser, but since the problems you are most likely to encounter with a specific browser are client-side, there should be no need to detect it from the server-side.
So here's a solution with javascript, and if you get the match you expect, you can hide the body, or display a popup, or send it to your server, set a cookie, or whatever you see appropriate to "fix" your problem (although you should be looking into really fixing the problem...)
Look here for the source:
function that_is_called_on_load() {
if (BrowserDetect.browser == "Chrome" && BrowserDetect.OS == "Mac") {
alert("You are using mac, sorry.");
window.location = "mac_chrome.php";
}
}
This is a very "dirty" solution, and it might be slightly more accurate/reliable than the server-side one.

browser name in php?

How can we get Browser Name and Version information using php script?
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>
As Palantir says, additionally have a look at the get_browser function, where you can check also capabilities enabled in the browser.
http://php.net/manual/en/function.get-browser.php
You will need to create function to translate user agent data into common names of browsers
For example, $_SERVER['HTTP_USER_AGENT'] could return
Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9* is firefox
or
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.55 Safari/533.4 is Chrome
The details provide you with the rendering engine, code base, version, os, etc...
I'd suggest using preg_match and/or a list of known browsers is you want to do something like
echo browserCommonName($_SERVER['HTTP_USER_AGENT']);
to output "Google Chrome".
browserCommonName($userAgent) would need a list of known browsers.
edit: just noticed get_browser buit into php does this, my bad for not reading the thread.
See get_browser().
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser(null, true);
print_r($browser);
?>
All in all, you can't. You can certainly try to get it, and you're almost certainly guaranteed to get something that looks like what you want; but there is absolutely no way of checking wether or not the information is correct. When you receive a user agent string, the browser on the other end could be truthful, or it could be lying. When dealing with users, always assume that it is, in fact, lying.
There is no "best way" to deal with this, but what you most likely want to do is test your site with a wide variety of browsers, use portable HTML and CSS techniques, and if you absolutely must, fill the holes with JavaScript.
Choosing what data to send to a browser based on what browser you think it is, is a Bad Idea™.
You could always take a look at the php function get_browser http://php.net/manual/en/function.get-browser.php. You will need $_SERVER['HTTP_USER_AGENT'] for this.
You may also want to take a look at Chris Schuld Browser Detection Class. http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php.html

Categories