Drupal 7 PHP cheatsheet
Get the NID of the current node
Assuming your code is running for a node page, the methods I see used most often in core/contrib modules are either using menu_get_object() or arg():
if ($node = menu_get_object()) {
// Get the nid
$nid = $node->nid;