There is a chance this is a bug, but I am pretty sure I must be overlooking something.

Basically JUri::base() is removing the subdomain path, this is in siteground with its Joomla staging enviroments, so the domain it should be getting is http://staging1.domain.com but instead it gets http://domain.com.

I tested JUri::base() in the template file, and it worked correctly, but in the custom component built for the site it does not.

Here is how it is being used:

$tmpFileName = md5($id.$Itemid.time()).'.pdf';

What the above code does is opens a generated pdf file (a pdf view) saves it to the tmp directory, then later in the script includes it as an attachment (deleting it afterwords).

If in this area i add JUri::base() to the email (so I can see what it is according to the email sent) it strips the subdomain, I have confirmed that the redirection to the controller that does this function is correct, but the reason the url comes out improper in only this function eludes me (JRoute works fine).

I cannot use JUri::base(true) as it is the server attempting to get the contents of the file, so without the url it cannot get the file correctly. Also I have checked for the $live_site variable in the configuration.php file and confirmed it is not a factor in this.

Most likely its something stupid I am overlooking, most likely right in front of my face and I will update the question with any findings as I go. So is there there anything that could cause this? Or has anyone ran into something similar?

Version is 3.3.1


Dived deeper and here are my findings.

  1. I was wrong on thinking it was JUri::base() completely, although I had seen that it was getting the wrong variable now I see no evidence of it, although the result is the same, it is getting information from the live site and not the staging site.
  2. I tested the execution of all the code and check the pdf generated when I go directly to the url that it generates, it creates the PDF perfectly, yet when done with the file_get_contents function it does something totally and completely different (grabs a pdf from the wrong url, even though the url seems to be correct and testing it worked).
  3. I noticed I used an htpasswd on the site, and since the file_get_contents function goes to the url from the server itself it needs to authenticate, so there was no way a pdf should of been generated in this staging enviroment in the first place. This confirms that the pdf is being generated from the live site that has no htpasswd.

1 Answer 1


I'm guessing that you have the "live_site" defined in your configuration file. In looking at the code for Juri::base() there is this if statement:

if (trim($live_site) != '')
    // build base url from the live_site setting
    // build base url from current scheme, host, and port

So if you have "live_site" set in your configuration, it appears that the system may use that instead of your current url.

(I've never actually seen this issue personally, so this could also be way off, but it looks promising.)

  • Yes, I did try to say in my question I looked for that, the biggest confusion is that it is fine in the template but not in the component, possibly some plugin is trying to change it? Seems unlikely but at this point my brain has exploded. Aug 7, 2014 at 16:08
  • Well I definitely did not read the question closely enough... Aug 7, 2014 at 18:33
  • Its fine, it definitely could help someone with a similar problem and that's more important then my question :) Hail Joomla! Aug 7, 2014 at 19:23
  • My only other thought is to try JUri::reset() first and see if that fixes it. If it does then something definitely hacked the "live_site" config to get JUri::base() to be something else. Aug 7, 2014 at 19:26
  • Still never solved this, hacked it to work with htaccess though. But this can answer it for some people. I feel its due to my environment so marking this the answer. Oct 15, 2014 at 23:17

Your Answer

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

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