Answer the question
In order to leave comments, you need to log in
Php, changing the values of $_SERVER or is mod_rewrite and analogues better?
How safe is it to modify the $_SERVER array in a script? Or rather REQUEST_URI, QUERY_STRING and the like.
Can the php developers make $_SERVER readonly in the future, maybe someone has studied this issue and there is information. I did not see such information in the off-doc.
It is necessary to make several rewrites without redirects, transparently for the user, there is only one entry point to the application, the apache server. Addresses should change approximately according to this pattern:
^item\.php\?id=(\d+) /base/item/$1
But there are a couple of points:
1. It is possible to leave Apache and, accordingly, rewrite rewrites to nginx, lighttpd, etc
2. I'm not very good at mod_rewrite, I can't do all the things, and with such a task, as far as I remember, additional fuss with conditioners and flags, with a swoop and an hour of googling, did not work out.
Just half an hour after the transfer of the project to a new engine, the customer remembered that the old addresses should be saved. In the Yii used by regular routing tools, this did not work out. Urgently made a rewrite in php. Now I'm thinking about the best way to do it. I will be glad to answer both php and mod_rewrite.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
You yourself wrote that you have one entry point, so drive there as you need. Why change $_SERVER for this?
the array $_SERVER is the same array in global visibility as, say, the newly created array $qwe = array(1,2,3) Its changes will not affect anything, except for the logic of the program you are doing.
Another thing is that if you need to change this array, then your logic is not correct. Make a wrapper over an array and operate on it.
You have to be careful when modifying built-in arrays. It is easy to get hard-to-localize bugs due to the fact that some functions (in particular, filtering) do not work with $_SERVER, $_POST arrays, etc., but with the internal representation of the request, from which arrays are generated only when the script starts.
In Zend Framework, and in many other frameworks, there is such a thing as a request object . You can change it as much as you like, and I think this is the right approach. PHP is no longer coded with global variables. There are patterns like the same request object, register.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question