// let him eat $ path [] = "some /../ path / to / file"; $ path [] = "/ other / path / to / file"; // and real allowed path $ restriced_path = dirname (__ FILE __). "/"; // get real paths $ real_path [0] = realpath ($ path1); // -> "/ path / to / your / restrict / path / to / file" $ real_path [1] = realpath ($ path2); // -> "/ other / path / to / file" // check them foreach ($ real_path as $ pathn) { if (($ r = strpos ($ pathn, $ restriced_path))! == false && $ r == 0) { echo "Path $ pathn is allowed"; } else echo "Path $ pathn is denied"; }
$ path = "/ dir / path / to / file"; $ path = ltrim ($ path, "\\ /"); $ path = strpbrk ($ path, "\\ /"); echo $ path;
Source: https://habr.com/ru/post/18070/
All Articles