duanben1324 2017-02-09 13:07
浏览 34
已采纳

使用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?

  • 写回答

1条回答 默认 最新

  • douzuo5504 2017-02-09 13:15
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退