Current URL path variable

You could just get the permalink and strip the home root from it-

$path = substr( get_permalink(), strlen( home_url("https://wordpress.stackexchange.com/") ) );