I'm writing a little module, and I need to call several pages of my site using drupal_http_request(), which accepts only absolute URLs. I don't want to add a variable to store the domain of the site, also because on my company we have proxy etc.

Which is the best way to add the domain of the site?

  • I'm not quite sure what you mean exactly, but have you looked at global $base_url ? – Beebee Jun 21 '12 at 11:25
  • Hello, and welcome to Drupal Answers. I guess you want the absolute URL of the web server from which you call drupal_http_request(). Is there any reason why you cannot use url('', array('absolute' => TRUE))? Did you try it? – kiamlaluno Jun 21 '12 at 12:37
  • If my page is "page" and I try to run $url = url('page', array('absolute' => TRUE)), $url seems to be http://default/page. – arrubiu Jun 21 '12 at 12:51
  • I can use $_SERVER['HTTP_HOST'] but I don't know if works always.. – arrubiu Jun 21 '12 at 13:09

Here is what I'm using in a similar situation, with $base_url as Baysaa mentioned above.

$path_to_file = '/path/to/feed.xml';
$base_url = $GLOBALS['base_url']; // Not sure if this line is necessary.
$file_over_http = $base_url . $path_to_file;
$http_result = drupal_http_request($file_over_http);
  • 2
    I think you can use GLOBAL $base_url as well. – Citricguy Sep 22 '12 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.