Hi,

Is there any way to transfer a website address to a page callback using the url?

Suppose I have the following code:

/**
 * Implementation of hook_menu().
 */
function modulename_menu() {
  $items['test/test'] = array(
    'title' => 'Do something with URL',
    'page callback' => 'some_callback',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function some_callback($url = '') {
   // Do something with the URL
}

Now if I visit the page:

http://DOMAIN/test/test/http://www.google.com 

then the value of the $url parameter will be "http:" only (because drupal separate parameters with /). Is there any way to make drupal "understand" that I actually need the whole url (e.g. I need the value of $url to be http://www.google.com) ?

Any ideas will be highly appreceated!

Regards,
Faaing99

Comments

faaing99’s picture

Since I cannot pass a full url (say: http://www.google.com/) as a url parameter to a callback menu function (because drupal will give me only the part until the first / encounter -> http:).

I found a way to pass the whole url. I've replaced the / with .. (each slash with two dots because a valid url cannot contain two dots after each other) in the redirecting function (instead of passing "http://www.google.com/" I simply pass "http:....www.google.com..").

Now the parameter of the callback function equals to "http:....www.google.com.." (each slash replaced with two dots), the callback function manipulates the url (replacing every two dots with a slash):

$url = str_replace('..', '/', $url);

And bingo! now the $url variable equals to "http://www.google.com/"

However, the method I used is somehow clumsy and not straight forward. Is there any better solution?

regards,
Faain99

Daniel S. Jackson’s picture

Wondering about the same thing, but will use a variant of your solution in the meantime. Thanks!