简体   繁体   English

PHP检查URL的根

[英]PHP check root of url

I am using below script to create sessions 我正在使用以下脚本创建会话

    $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

    if (
        false !== strpos($url,'home') || 
        false !== strpos($url,'display-job') || 
        false !== strpos($url,'search-results-jobs') ||
        false !== strpos($url,'find-jobs') ||
        false !== strpos($url,'edit-profile1') ||
        false !== strpos($url,'my-account/?myacount=1')
        ) 
        {
            $_SESSION['page_name'] = 'jobseeker';
        } 
    else {
        $_SESSION['page_name'] = 'employer';
    }

I can use the above script to check if someone is on one of the following sub pages but the problem is that i want to trigger a different session when someone is on the root of the webpage and I cant figure a way out. 我可以使用上面的脚本来检查某人是否在以下子页面之一上,但是问题是当某人位于网页的根目录下并且我想不出办法时,我想触发另一个会话。

try this 尝试这个

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$root_url = 'http://' . $_SERVER['SERVER_NAME'];

$arr_url = explode("/", $url);
unset($arr_url[sizeof($arr_url)-1]);
$new_url = implode("/",$arr_url);


if($new_url==$root_url)
{
    // do your work
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM