Here is a more reliable way to get the node identifier:
<?php
This method works even if you have your own path for node with path and / or pathauto .
Just for reference, if you don't include the path module, the default URLs that Drupal creates are called "system paths" in the documentation. If you enable the path module, you can set custom paths called โaliasesโ in the documentation.
Since I always had the path module turned on, at first I was embarrassed that the arg function could always return part of the alias, and not part of the path to the system.
As it turned out, the arg function will always return the system path, because the arg function is based on $_GET['q'] ... After a little research, it seems that $_GET['q'] will always return the system path.
If you want to get the path from the actual page request, you need to use $_REQUEST['q'] . If the path module is enabled, $_REQUEST['q'] can return either an alias or a system path.
mparker17
source share