我在URL.php中创建了一个名为URL的类
现在我有:
这被称为检查是url true,现在只是真的。
public function isValid() {
return $this->aa(ltrim($_SERVER['REQUEST_URI'], '/'), self::getUriData());
}
我在这里检查是从数组数组中的uri传递路径
public function aa($path, $uriData) {
$path = explode('/', $path);
if(!isset($uriData[$path[0]]) && $path[0]!==""){
$uriData = false;
}else if($path[0]==""){
$uriData = true;
}else{
foreach ($path as $bit) {
if(isset($uriData[$bit])) {
$uriData = $uriData[$bit];
}else if(ctype_alnum($bit)){
$bit = 'alphanumeric';
if(isset($uriData[$bit])) {
$uriData = $uriData[$bit];
}
}else if(is_numeric($bit)){
$bit = 'numeric';
if(isset($uriData[$bit])) {
$uriData = $uriData[$bit];
}
}
}
}
return $uriData;
}
这只是从一些由十六进制代码编写的文件中获取数组...
public static function getUriData() {
//Hash is called from different file and there is no problem with that
$c = Hash::getHexData('valid-uri-dev');
$a = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $c), true);
return $a;
}
getUriData()正在返回:
array(
"users" => array(
"" => true,
"alphanumeric" => true,
"numeric" => true,
"messages" => true,
"friends" => array(
"all" => true,
"same" => true
)
),
"admin-dev" => true
);
在 index.php 文件中我有:
$url = new URL;
if($url->isValid()) {
var_dump($url->isValid());
}else echo 'This page does not exist!';
现在我的问题出在 aa(),看看:
如果我的网址是:
www.something.com - 返回true
www.something.com/32131132 / - 返回不正确(idk null或其他内容)
www.something.com/dasdasadsa312312 / - 返回不正确
www.something.com/users / - 返回true
www.something.com/users/4h43h234 / - 返回true,因为如果它存在于数组中,我首先检入循环,但如果不存在则返回字母数字或者如果它返回真实
但现在在这种情况下:
www.something.com/users/friends/43243242ngjggj / - 也返回true,但在$value
数组中没有{{1} }选项,但它仍然返回true
我在这里做错了什么?
由于