tags:

views:

9188

answers:

7

Hi all,

I need to be grabbing the URL of the current page in a Drupal site. It doesn't matter what content type it is - can be any type of node.

I am NOT looking for the path to theme, or the base url, or Drupal's get_destination. I'm looking for a function or variable that will give me:

http://mydrupalsite.com/node/number

In full. Either with or without (more likely) the http://

Thanks guys! I'm sure this is something simple but my Google-fu isn't so hot on this one.

A: 

Maybe what you want is just plain old predefined variables

Consider trying

$_SERVER['REQUEST_URI'']

Or read more here

Sergej Andrejev
this gives /node/number, he wants (http://)mydrupalsite.com/node/number
ax
+6  A: 

drupal_get_destination() has some internal code that points at the correct place to getthe current internal path. To translate that path into an absolute URL, the url() function should do the trick. If the 'absolute' option is passed in it will generate the full URL, not just the internal path. It will also swap in any path aliases for the current path as well.

$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$link = url($path, array('absolute' => TRUE));
Eaton
according to your link, drupal_get_destination() returns "destination=/node/number" or, for /node/number?destination=bla, "destination=bla". passing this to url() doesn't seem to work to me.
ax
Doh. You're correct. I've updated the snippet with the correct code. Thanks!
Eaton
+2  A: 

try

url($_GET['q'], array('absolute' => true))

ax
+2  A: 

This is what I found to be useful

global $base_root;
$base_root . request_uri();

Returns query strings and it's what's used in core: page_set_cache()

mikeytown2
A: 

nice.

global $base_root;
$base_root . request_uri();

saved me a lot of headache - Thank you!

chris

Chiefs Hockey
+2  A: 

You can also do it this way :

$current_url = 'http://' .$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];

It's a bit faster.

ThomasR
A: 

Cool, but I had to add:

$echo link;

for a facebook app to work!

Thanks!

Matt