使用php定位子目录
I am running an argument based on urls to determine whether a user can access that area or not of the site. Is there a better way to instead of listing our every url just say anything after /
cant be access. Here is my code it will better explain the problem:
if( $siteUrl == '/shop-portal/' && $userRole == 'customer'){
header('Location: http://mywebsite.co.uk/');
} elseif( $siteUrl == '/product-category/...' && $userRole == 'customer'){
header('Location: http://mywebsite.co.uk/');
}
so where I have /product-category/
isa there a way instead of writing out '/product-category/category1
etc etc every time can I just create one argument? Like anything after '/product-category/...' gets redirected?
我正在运行基于网址的参数,以确定用户是否可以访问该网站的该区域。 有没有更好的方法来代替列出我们的每个网址只是在 所以我有 / code>访问后说什么。 这是我的代码,它将更好地解释问题: p>
nn if($ siteUrl =='/ shop-portal /'&& $ userRole =='customer') {
header('Location:http://mywebsite.co.uk/');
} elseif($ siteUrl =='/ product-category / ...'&& $ userRole =='customer '){
header('Location:http://mywebsite.co.uk/');
}
/ product-category / code>是否有一种方法而不是写出
'/ product-category / category1 code>等等,每次我可以创建一个参数? 就像'/ product-category / ...'被重定向后的任何东西一样? p>
div>
I figured it out, here if any one else needs to see it:
if(strpos($siteUrl, 'shop-portal') !== false && $userRole == 'customer'){
header('Location: http://mywebsite.co.uk/');
} elseif(strpos($siteUrl, 'product-category') !== false && $userRole == 'customer'){
header('Location: http://mywebsite.co.uk/');
}
I changed up the query to check if the string exists in the url!