I am currently working with an existing project that is for maintenance. So per testing, there's a scenario that is having an error
Request-URI Too Large
The requested URL's length exceeds the capacity limit for this server.
This is error happens because our clients uses the GET method, and I don't wanna change their settings since there are other complex logic that might be affected. So I tried the approach to change the URL using javascript but still the same error. Now what I'm thinking, is it possible for us to change the URL in the controller? Like use the url current path:
url()->current();
rather than the fullpath ?
url()->full();
I badly need your help on this one, I'm stuck on this part for days already.
Under Apache, the limit is a configurable value, LimitRequestLine. Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf. If not, add a new line (LimitRequestLine 10000) under AccessFileName .htaccess.
However, note that if you're actually running into this limit, you are probably abusing GET to begin with. You should use POST to transmit this sort of data -- especially since you even concede that you're using it to update values. If you check the link above, you'll notice that Apache even says "Under normal conditions, the value should not be changed from the default."
Related
I am writing a small script in which it redirects to country specific landing pages(example: if you come from Germany you will be re-directed to xyz.com/de/) this redirection happens using index.php which connects to web service returns the country the user is accessing the website from then I redirect the user using 301 to a the new page xyz.com/de/
I have two questions
1- Can the same functionality integrated with mod_rewrite, if so what is the advantage in terms of performance and SEO quality?
2- Can the mod_rewrite save the query string including GCLID on the redirects (as I am concatenating the $_SERVER to php redirection
You can install mod_geoip on your server, which enables database-based geolocation lookup directly inside Apache. Look at the examples for exactly the scenario you talk about.
The advantage would be much better performance, since the lookup will be done locally using a database, instead of needing to call an external web service. It also requires virtually no code once this is set up, easing maintenance. You will only have to make sure your local copy of the lookup database is regularly updated, typically with a weekly/daily cron job.
You can rewrite the URL in any way you want appending any parameters you want.
SEO-wise it should have no effect at all compared to PHP based redirects, since to the client the behaviour appears exactly the same.
mod_rewrite can't do geolocation, nor can it connect to an external service
If your PHP code is doing the 301 redirect, then you'll need to preserve the query string in your PHP code. If you have an htaccess rule doing the 301 redirect, then the query string should be passed through with the redirect.
The documentation states:
Modifying the Query String
By default, the query string is passed through unchanged. [...] When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.
In answer to question 1.
You can do the Geo IP direction in the vhost Apache configuration if you have mod_geoip/mod_geoip2 installed.
You can also do it using mod_rewrite if the mod_geoip/mod_geoip2 installed.
In answer to question 2.
You can use mod_rewrite to keep the existing query string on the rewritten url there are some examples of this here
For caching purposes, I need to check whether sql returned set of data has changed. HTTP_IF_MODIFIED_SINCE will check if the file code has changed (correct me if I am wrong). I need a way to check if the sql returned results has changed? what's the best approach/way to do so? Thanx.
I need to check whether sql returned set of data has changed
The real answer is: you can't :)
How can you tell that data has changed, when you did not check back? Correct - you just simply cannot tell!
Adjust your cache time according to your presumption, when the data might have changed. There is no easy way to decide this. Caching means to weigh up between how costly it is to fetch fresh data from the database and how long you (your users) can live with probably old data, and not every piece of data is as well cacheable as others.
The database itself uses query caches and should be able to serve an unchanged resultset from its cache (doing it much more intelligent as PHP could possibly do it). However, in a multiuser environment those caches tend to be freed early because of heavy database traffic. Here you can help out with your very own caching strategy.
u can use MD5(str);
if(md5($lastsql)==md5($nowsql)){}...
md5 description
HTTP_IF_MODIFIED_SINCE will check if the file code has changed (correct me if I am wrong)
The If-Modified-Since header tells the application to respond with a 304 status code if it can determine that the resource hasn't changed since the specified date.
For static files, usually the web server handles this itself, and the modification date is the modification date of the static file.
For non static resources, like a PHP script, the application (i.e. your code) has to handle the If-Modified-Since header itself. Most applications don't. Applications implementing this usually refer to the modification of the data, not the code.
You are probably doing "Optimistic Concurrency Control". This usually involves a "version" field in the database, which then you can use as the "etag" in HTTP. (the keyword there is "conditional GET")
I am trying to trace the flow of execution in some legacy code. We have a report being accessed with
http://site.com/?nq=showreport&action=view
This is the puzzle:
in index.php there is no $_GET['nq'] or $_GET['action'] (and no
$_REQUEST either),
index.php, or any sources it includes, do not include showreport.php,
in .htaccess there is no url-rewriting
yet, showreport.php gets executed.
I have access to cPanel (but no apache config file) on the server and this is live code I cannot take any liberty with.
What could be making this happen? Where should I look?
Update
Funny thing - sent the client a link to this question in a status update to keep him in the loop; minutes latter all access was revoked and client informed me that the project is cancelled. I believe I have taken enough care not to leave any traces to where the code actually is ...
I am relieved this has been taken off me now, but I am also itching to know what it was!
Thank you everybody for your time and help.
There are "a hundreds" ways to parse a URL - in various layers (system, httpd server, CGI script). So it's not possible to answer your question specifically with the information you have got provided.
You leave a quite distinct hint "legacy code". I assume what you mean is, you don't want to fully read the code, understand it even that much to locate the piece of the application in question that is parsing that parameter.
It would be good however if you leave some hints "how legacy" that code is: Age, PHP version targeted etc. This can help.
It was not always that $_GET was used to access these values (same is true for $_REQUEST, they are cousins).
Let's take a look in the PHP 3 manual Mirror:
HTTP_GET_VARS
An associative array of variables passed to the current script via the HTTP GET method.
Is the script making use of this array probably? That's just a guess, this was a valid method to access these parameter for quite some time.
Anyway, this must not be what you search for. There was this often misunderstood and mis-used (literally abused) feature called register globals PHP Manual in PHP. So you might just be searching for $nq.
Next to that, there's always the request uri and apache / environment / cgi variables. See the link to the PHP 3 manual above it lists many of those. Compare this with the current manual to get a broad understanding.
In any case, you might have grep or a multi file search available (Eclipse has a nice build in one if you need to inspect legacy code inside some IDE).
So in the end of the day you might just look for a string like nq, 'nq', "nq" or $nq. Then check what this search brings up. String based search is a good entry into a codebase you don't know at all.
I’d install xdebug and use its function trace to look piece by piece what it is doing.
EDIT:
Okay, just an idea, but... Maybe your application is some kind of include hell like application I’m sometimes forced to mess at work? One file includes another, it includes another and that includes original file again... So maybe your index file includes some file that eventually causes this file to get included?
Another EDIT:
Or, sometimes application devs didn’t know what is a $_GET variable and parsed the urls themselves -> doing manual includes based to based urls.
I don't know how it works, but I know that Wordpress/Silverstipe is using is own url-rewriting to parse url to find posts/tags/etc. So the url parsing maybe done in a PHP script.
Check your config files (php.ini and .htaccess), you may have auto_prepend_file set.
check your crontab, [sorry I don't know where you would find it in cpanel]
- does the script fire at a specific time or can you see it definitely fires only when you request a specific page?
-sean
EDIT:
If crontab is out, take a look at index.php [and it's includes] and look for code that either loops over the url parameters without specifically noting "nq" and anything that might be parsing the query string [probably something like: $_SERVER['QUERY_STRING'] ]
-sean
You should give debug_backtrace() (or debug_print_backtrace() a try. The output is similar to the output of an Exception-stacktrace, thus it should help you to find out, what is called when and from where. If you don't have the possibility to run the application on a local development system, make sure, that nobody else can see the output
Are you sure that you are looking at the right config or server? If you go the url above you get an error page that seems to indicate that the server is actually a microsoft iis server and not an apache one.
My problem is not so easy to describe ... for me :-) so please be lenient towards me.
I have several ways to view a list. which means, there are some possibilities how to come to and create the view which displays my list. this wokrs well with parallel opend browser tabs and is desired though.
if I click on an item of my list I come to a detail-view of that item.
at this view I want to know from which type of list the link was "called". the first problem is, that the referrer will allways be the same and the second: I should not append a get variable to the url. (and it should not be a submitted form too)
if I store it to the session, I will overwrite my session param when working in a parallel tab as well.
what is the best way to still achive my goal, of knowing which mode the previous list was in.
You need to use something to differentiate one page from another, otherwise your server won't know what you're asking for.
You can POST your request: this will hide the URL parameters, but will hinder your back button functionality.
You can GET your request: this will make your URLs more "ugly" but you should be able to work around that by passing short, concise identifiers like www.example.com/listDetail?id=12
If you can set up mod_rewrite, then you can GET requests to a url like www.example.com/listDetails/12, and apache will rewrite the request behind the scenes to look more like www.example.com/listDetails?id=12 but the user will never see it -- they will just see the original, clean/friendly version.
You said you don't have access to the server configuration -- I assume this is because you are on a shared server? Most shared servers already have mod_rewrite installed. And while the apache vhost is typically the most appropriate place to put rewrite rules, they can also be put in a .htaccess file within any directory you want to control. (Sometimes the server configuration disables this, but usually on a shared host, it is enabled) Look into creating .htaccess files and how to use mod_rewrite
When calling the following type of url in a controller's init method I get two different results on two different servers:
http://address.com/index/action/?start=2009-04-18&end=2009-04-21
Calling
echo $_GET['start'];
Gives me 2009-04-18 on one server and nothing at all on the other server.
However, and this is the strange part, adding
exit();
after that echo statement causes 2009-04-18 to display as expected on both servers.
FYI dumping the request params shows they are available on the one server but not on the other... unless you call exit();
What in the world could be causing this? I realize this isn't the way to structure URLs in ZF but it is the way it is being done in this particular project. Maybe a custom route of some sort would help? STill doesn't explain the exit(); bit causing the $_GET variable to display.
EDIT: In order to get around this for now I wrote a custom route, however the ? in the url messes things up. By including it it appears that the GET variable is forced and overrides my custom route. Leaving it out, everything works fine in the route I created but I don't have the option to remove that ?. Anyone know how to make the custom route take precedence over the GET variables being populated when that ? is in there?
My guess is the $_GET['start'] is actually working on both servers, the problem is the one that shows nothing is having a problem AFTER this statement, but the output from the echo is still in the output buffer. If you do a flush() after the echo, you should be able to see the output, then whatever crashing afterwords will still crash but you will see the date.
I'm not sure what you're doing with the routing(not enough code to see), but your query string(everything after the ?) is totally different from your routes. If you're going to use routing, you'll want to enable mod_rewrite by using the provided .htaccess file on the ZF Quickstart page.
I think you'll want to make your own custom Router(not just a Route), and then use the $_GET parameters to route to the controller you want, along with the parameters it needs. The default Router doesn't do complicated things with the QueryString, at least not the last time I checked.
Check your .htaccess file on the broken server.
http://framework.zend.com/manual/en/zend.controller.router.html