Unknown Str_Replace On URL
I am trying to understand this one line of code below:
str_replace('../', '', $route);
Basically it says replace '../'
with nothing in $route
$route = 'information/information&information_id=4';
from the url 'index.php?route=information/information&information_id=4'
But there is no ../ in the $route variable. Is 开发者_高级运维it some sort of regex? If yes, what does it exactly do. Thanks guys.
You are correct in thinking that it replaces "../"
with an empty string. It is not regex. There is no occurence of it in your example, but there could be.
It might be used for some sort of security to prevent you from going back up the directory structure from the document root.
If there's no ../
in the string, this will replace nothing. It's not a regex (see preg_replace()
for that. It's just precaution against someone trying to pass invalid path (starting with ../
), which could potentially be an attempt of accessing files outside of webserver's document root (in other words, a hacking attempt).
精彩评论