Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By superjoe-1 on
hi,
how do I get the url of the current page in a phptemplate based theme?
Comments
I think you can use this code
I used this in my "Back to Top" link code:
<a href="/<?php print url($_GET['q'], NULL, NULL, TRUE); ?>#top">Back to top</a>
"Extraordinary claims require extraordinary evidence"
-- Carl Sagan
This works for me:
drupal_get_path_alias(request_uri())
That's in 4.6.5. Not sure about other versions.
Thank you willis
That code also works in templates on D6
that will work on all versions
this code does not use drupal's own functions or variables, which will work well on all php projects. Replace "http://" with "https://" if your site is using ssl connection.
that will work on all versions
this code does not use drupal's own functions or variables, which will work well on all php projects. Replace "http://" with "https://" if your site is using ssl connection.
that will work on all versions
this code does not use drupal's own functions or variables, which will work well on all php projects. Replace "http://" with "https://" if your site is using ssl connection.
I've been using $this_page =
I've been using
$this_page = $_SERVER['REQUEST_URI'];
to get just the name of the currently displayed page without the domain path. This seems to always give me the name as drupal sees it *after* pathauto has done it's thing.request_uri() function
The request_uri() function from bootstrap.inc looks like it automatically generates the required information, taking a different approach depending on what is available on the host platform:
http://api.drupal.org/api/function/request_uri/5
I've used it successfully.
Read 'Free Software - Free Society' by RM Stallman
In addition request_uri
In addition request_uri should need to be used without the base_path part, it is useful specially for determining or setting current menu item (menu_set_active_item($path));
--
(3 John 1:2) Dear friend, I pray that you may enjoy good health and that all may go well with you, even as your soul is getting along well.
--
develCuy
Hiring the next generation front-end devs, contact Dilygent
in combination with drupal_goto()
Just a tip: I found myself using this with drupal_goto() (http://api.drupal.org/api/function/drupal_goto/5) to reload the current page on form submission. However, when using request_uri from a view or any URL with query it needs to be broken up into the path and the query parts for drupal_goto to compute it properly. The following if statement detects if the URL contains a query and if it does it breaks it up accordingly. Might save someone some time:
--
Technology, Society and Economics in Latin America
http://altate.ch
--
Neil Cameron
substr() and strpos() usage
You don't need to give substr() a third argument if you want to just remove the first character of a string. Thus, your substr() line could look like:
Also, using !==0 will trigger that if statement whenever there is no '?' in the URI because strpos()'s return value of FALSE is not strictly equal to 0. You probably want
Or, simpler, just the one-liner:
list() will assign NULL (which looks like '' when cast to a string) to $query if there is not a query section in $this_page. Avoiding the conditional (the if()) and its search through $this_page (which ends up being redundant with explode()'s search for '?') would seem to be more efficient ;-).
Make sure the URL is clean?
Sorry, this is a bit of a newbie question, but I thought I should ask, is there a preferred way from a Drupal perspective to make sure this URL is "clean", and not some malicious user hack attempt? That is, if I get the URI like this:
is it a correct practice to process this URI through one of the methods on the Drupal secure coding page (http://drupal.org/writing-secure-code) before using it? The check_plain() method looks like it will encode the string, which is my major concern.
Thanks,
Al
http://devdaily.com
make sure url is clean
I'm using
$curr_uri = check_plain(request_uri());
to make sure the url is clean.I think
I think check_url is better
KOBA - Drupal Webdesign & Webdevelopment
Ensuring URLs are clean
When playing with a URL in your code, you should always keep it in the `unclean' format until you render it for the user.
To ensure that it is clean at that point, you should really use something appropriate for the situation:
Here I use
%
which means that the value was obtained from the user and is being displayed to the user. In other cases where I need the URL included in t() but verbatim and only escaped, I would've used@
.without language prefix?
This will return /es/etc for spanish pages. What if I don't want the language prefix? I found two api functions that will work fine: