phpdrupaldrupal-7drupal-themingdrupal-9

How to get current page URL in Drupal?


I'm trying to output the current page URL on a Drupal site (Drupal 7), I've tried the following...

<?php print current_path(); ?>

Which outputs the page name but not the URL, any ideas on how to output the full URL too?


Solution

  • In straight PHP you can use this:

    $curPathName = $_SERVER["DOCUMENT_ROOT"];
    $currentURL = $_SERVER["HTTP_HOST"];
    

    I don't see why that wouldn't work. That will give you the path and the URL.