PHP

Get second segment from url

Pinterest LinkedIn Tumblr

$uri_path = parse_url($_SERVER[‘REQUEST_URI’], PHP_URL_PATH);
$uri_segments = explode(‘/’, $uri_path);

echo $uri_segments[1]; // for www.example.com/user/account you will get ‘user’

Write A Comment