How to get nid from URL alias in drupal 7? I have a URL alias sitepath/john/video/nature-beauty where john = user, video = content type and nature-beauty = node. I am trying to get nid of node nature-beauty. Node title is "Nature beauty" actually. I have set node title in URL alias.

Can anyone tell me where am I wrong in below code?

   $last_page_visited = $_SERVER['HTTP_REFERER'];
   $alias =$last_page_visited;
   $path = drupal_lookup_path("source", $alias);
   $node = menu_get_object("node", 1, $path);
   $nid=$node-&gt;nid;
   print $nid;
The $_SERVER['HTTP_REFERER'] will return the full URL, but the function drupal_lookup_path() takes only the alias as argument, so parse you URL and pass only the alias, john/video/nature-beauty then it will work.

$url = $_SERVER['HTTP_REFERER'];
$path = preg_replace('/\//','',parse_url($url,PHP_URL_PATH),1);
$org_path = drupal_lookup_path("source", $path);
$node = menu_get_object("node", 1, $org_path);
$nid=$node-&gt;nid;
print $nid;