What will happen after this request in php - 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"

Related

Issue with & in URL using simplexml_load_file

simplexml_load_file() does not load XML file when the URL includes an ampersand symbol. I have tried two examples with and without ampersand:
$source1 = simplexml_load_file("http://www.isws.illinois.edu/warm/data/outgoing/nbska/datastream.aspx?id=ncu");
print_r($source1); //works
$source2 = simplexml_load_file("http://forecast.weather.gov/MapClick.php?lat=38.8893&lon=-77.0494&unit=0&lg=english&FcstType=dwml");
print_r($source2); //no output
First example works well as it does not includes ampersand, but the second example does not work as it include ampersand.
I have referenced
simplexml_load_file with & (ampersand) in url with Solr and simplexml_load_file ampersand in url but it did not work.
The issue is not the ampersand in the URL. The issue, instead, is that weather.gov appears to be blocking these types of requests. They will not allow users that do not have a useragent set.
The fastest way to get around this is to set a UserAgent within PHP, which you can do by putting this code above your xml call:
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20100101 Firefox/9.0');
However, I would recommend using CURL instead of simplexml_load_file, as simplexml_load_file is often restricted by server configuration. If you were to do this with curl, you'd want to do something like the first answer here:
SimpleXML user agent
I have tested this locally and got it working just by specifying a user agent.
EDIT: Also, welcome to SO! Be sure to vote often ;D

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 to get browser name in cakephp 3 request?

I need to get requesting browsers name in my web app.( for analytics )
In core php when I use $visitor_user_agent=$_SERVER['HTTP_USER_AGENT']it returns Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36 string when using with chrome.And then preg_match('/Chrome/i', $visitor_user_agent) can be used to know if its chrome or not.I am not sure if that was efficient way to find browser name or not.
I also found get_browser link but it is not giving browser name.
Is there a way in cakephp3 or core php to get browser name ?
This would return the user agent used for the request:
$this->request->header('User-Agent');
http://book.cakephp.org/3.0/en/controllers/request-response.html
Look into documentation of Request object.
You can get HTTP_USER_AGENT using env() method:
$this->request->env('HTTP_USER_AGENT');
You can also prepare custom detector:
$this->request->addDetector(
'chrome',
['env' => 'HTTP_USER_AGENT', 'pattern' => '/Chrome/i']
);
And then in controller just use is() method as follows:
if($this->request->is('chrome')) {
// do stuff for chrome
}

Who Add "_" Single Underscore Query Parameter?

I have a PHP server running on Apache, I get lots of request looks like this,
10.1.1.211 - - [02/Sep/2010:16:14:31 -0400] "GET /request?_=1283458471913&action=get_list HTTP/1.1" 200 547 0 "http://www.example.com/request" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)" 28632 15602
The _ parameter is mysteriously added to the request. I am trying to find out who is doing that.
There is a NetScaler running in front of Apache.
jQuery adds a parameter like that to get around IE's caching.
edit:
it only adds it for get requests, and only if the option cache is false:
cache: false
It could be the JQuery CacheBuster parameter.
Resources :
[jQuery] GData JSON queries "Invalid query parameters:_"
[jQuery] Turn off Cache Busting in $.getScript
Cache-busting
Probably it's a dummy parameter added by the reverse proxy to force non-cached content to be served.
1283458471913 is a unix timestamp in ms, probably a bot/proxy making sure that they get a fresh page and not a cached version.
Could also be jQuery which would cause this for AJAX request of you have the nocache attribute set to true.
if ( s.cache === false && type == "GET" ) {
var ts = now();
// try replacing _= if it is there
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2″);
// if nothing was replaced, add timestamp to the end
s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
}
Ajax tools, like jQuery, is able to ask the browser not to cache the requested result, so every request from the loaded web page will travel to web server and get the newest response.
In order to achieve that, set cache flag as false, then an additional query parameter, like _=1234567890, is appended into the request URL. Of course the number is always changing, so the browser thinks it as a brand-new request and won't provide any cached things.

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