too long

I am new to drupal coding and still fairly new to PHP. I have gotten myself to a certain point, and am now stuck! The documentation has helped me a lot up to this point, but I find myself struggling to make it over this hurdle.

My Code:

<?php

//Pulls the refering page url
$prev_page = $_SERVER['HTTP_REFERER'];

//breaks the referer into an associated array
$delimit = '/';
$splode = explode($delimit,$prev_page);

$chunked = array_slice($splode, 3, NULL);


//iterates through the array to output the address as a string
foreach($chunked as $k=>$v){
$path .=  $v."/";
}

//find the node id from the alias
$node = drupal_get_normal_path($path);
echo $node;

?>

So I have gotten the refering page address to be just the extension (ie: about-us/tim rather than http://www.google.com/about-us/tim ) to pass into drupal_get_normal_path.

I have put the actual uri into the drupal_get_normal_path and received the node information that I had expected to get, but when I use the variable as shown in the code block above it returns the text that is stored in the variable instead of finding the node source.

Any help ya'll can give is greatly appreciated!

Think this is fairly similar to this question here.

What you're doing wrong is assuming that that function returns a node - it doesn't, just returns the internal path to that node. So you still have to get the object (the node) referenced by that URL and then you actually have the node id.

Basically, you can achieve it using (this code is slightly more efficient and compact than what you have - plus it works!):

$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->nid;
print $nid;

If you actually want to load the node, you just do node_load($nid) after all this.

Hope this helps!