Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 303 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the full URL of a Drupal page?

#1
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 the following in full:

[To see links please register here]


Either with or without (more likely) the `http://`.
Reply

#2
[drupal_get_destination()][1] 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()][2] 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));

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
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()][1]


[1]:

[To see links please register here]

Reply

#4
I find using tokens pretty clean.
It is integrated into core in Drupal 7.

<?php print token_replace('[current-page:url]'); ?>
Reply

#5
This method all is old method, in drupal 7 we can get it very simple

current_path()


-

[To see links please register here]

returns "node/306".
-

[To see links please register here]

returns "node/306" while base_path() returns "/drupalfolder/".
-

[To see links please register here]

(which is a path alias for node/306) returns "node/306" as opposed to the path alias.

and another function with tiny difference

request_path()

-

[To see links please register here]

returns "node/306".
-

[To see links please register here]

returns "node/306" while base_path() returns "/drupalfolder/".
-

[To see links please register here]

(which is a path alias for node/306) returns "path/alias" as opposed to the internal path.
-

[To see links please register here]

returns an empty string (meaning: front page).
-

[To see links please register here]

returns an empty string.

Reply

#6
You can also do it this way:

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

It's a bit faster.
Reply

#7
Try the following:

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

#8
The following is more *Drupal-ish*:

url(current_path(), array('absolute' => true));
Reply

#9
Maybe what you want is just plain old predefined variables.

Consider trying

$_SERVER['REQUEST_URI'']

Or read more [here][1].


[1]:

[To see links please register here]

Reply

#10
**For Drupal 8** you can do this :

$url = 'YOUR_URL';
$url = \Drupal\Core\Url::fromUserInput('/' . $url, array('absolute' => 'true'))->toString();
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through