1

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?

4
  • I'm not quite sure what you mean exactly, but have you looked at global $base_url ?
    – Beebee
    Jun 21, 2012 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?
    – apaderno
    Jun 21, 2012 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, 2012 at 12:51
  • I can use $_SERVER['HTTP_HOST'] but I don't know if works always..
    – arrubiu
    Jun 21, 2012 at 13:09

1 Answer 1

3

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);
1
  • 2
    I think you can use GLOBAL $base_url as well.
    – Citricguy
    Sep 22, 2012 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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