Chrome mobile loads PHP twice? - php

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.

Related

What will happen after this request in php

I see some weird code in a site. I am very confused about this. There is the http request that I tested my own server:
http://192.168.1.3/folder/ui/login_html.php/TEST/TEST
The folder named login_html.php and TEST are not exist.I checked the debug information for Chrome.It can properly request files but cannot parse it.debug information
.
It seems that will request all css and js resources which referenced in the login_html.php, And the request is initiated by TEST.
By the way, I did nothing in login_html.php, I just reference files and write some html code.
There is an apache information in access_log and nothing in error_log:
"GET /cos/ui/login_html.php/TEST/js/cloudmanager.js HTTP/1.1" 200 9564 "http://192.168.1.3/cos/ui/login_html.php/TEST/TEST" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
I am confused about this.And can someone explain it?
Everything after the ? is the query string.
Often this contains variables in the form var1=value1&var2=value2. In that case, PHP parses these automatically and puts them in the $_GET array.
In your example the query string doesn't contain a normal set of variables, so the $_GET array would likely be little use. However, you could just get the entire query string from the $_SERVER array.
$var = $_SERVER['QUERY_STRING'];
// $var would be "/HOME/getVersion"

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.

Codeigniter User Agent detect Opera browser as Chrome

I'm trying to show the browser that I used to open my site using Codeigniter User Agent Libraries. When I open with IE,Chrome,Firefox,and Safari, User agent return the right value. But when I open with Opera, it return "Chrome" value.
here is part of my code:
Controller
*** another code ***
$this->load->library('user_agent');
$data['browser'] = $this->agent->browser();
$this->load->view('agent',$data);
*** another code ***
View
Your browser is <span><?php echo $browser; ?></span>.
the result if I open with opera is this:
Your browser is Chrome.
My question is, why it return Chrome? How can I fix this problem?
Thanks.
It looks like the user agent string in opera (since version 15) is this:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100
You might need to extend the user_agent library to do a check to see if the user agent string contains OPR.
https://dev.opera.com/blog/opera-user-agent-strings-opera-15-and-beyond/

How to detect dolphin browser in 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.

Detect on which browser current web application is running

I wanted to know in PHP, how to detect on which browser my web application is running.
e.g.
If current browser is chrome then alert("Chrome browser processing") otherwise alert("rest browser processing");
echo $_SERVER['HTTP_USER_AGENT'];
Below output I am getting If i execute above code :
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.21 Safari/532.0
Please suggest your pointers to detect exact browser name.
Thanks,
-Pravin
This has some useful code.
Basically, in your case, you can just look for the string "Chrome". In general, it might take a bit more logic, since, for example, the string "Safari" is found in the user-agents provided by other browsers than Safari (including Chrome). PHP provides the 'browser' element for this.
Personally, I'd use Javascript for this one.
if(navigator.userAgent.match(/Chrome/i)) {
alert("You're using Chrome!");
}
else {
alert("You're using something other than Chrome!");
}
... but if you really wanted to, you could accomplish the same thing in PHP:
if (preg_match("/Chrome/i", $_SERVER['HTTP_USER_AGENT']) == 0) {
// zero matches
echo "<script>alert('You're not using Chrome!')</script>";
} else {
echo "<script>alert('You're using Chrome!')</script>";
}

Categories