Page 1 of 1

get base url to use in external script

Posted: Thu Jan 15, 2009 10:52 am
by ademc
Hi guys,

I need the joomla 1.5 base url to use as a path in an external script, but I'm not sure what I need to include to get access to the variable.

Thanks in advance

Re: get base url to use in external script

Posted: Thu Jan 15, 2009 3:43 pm
by MyJC

Code: Select all

baseurl()

Re: get base url to use in external script

Posted: Thu Jan 15, 2009 5:53 pm
by rfriedel
Or better yet use...

Code: Select all

JURI::base();
So if you wanted to output a full url to the clock image named clock.jpg that is located in the images/stories/ you could do so like this...

Code: Select all

$path = 'images/stories/';
$filename = 'clock.jpg';
$myImgUrl = JURI::base() . $path . $filename;

echo $myImgUrl;
/*
 * Assuming your Joomla! install is in the topmost directory the output would be
 * http://yoursite.com/images/stories/clock.jpg
 */
Some cavets here...
The class is JURI not JURL
JURI::base() has the trailing slash so you need to leave it out of the beginning of your path

Edit: misspelled JURI lol

Re: get base url to use in external script

Posted: Thu Jan 15, 2009 10:07 pm
by ademc
rfriedel wrote:Or better yet use...

Code: Select all

JURI::base();
So if you wanted to output a full url to the clock image named clock.jpg that is located in the images/stories/ you could do so like this...

Code: Select all

$path = 'images/stories/';
$filename = 'clock.jpg';
$myImgUrl = JURI::base() . $path . $filename;

echo $myImgUrl;
/*
 * Assuming your Joomla! install is in the topmost directory the output would be
 * http://yoursite.com/images/stories/clock.jpg
 */
Thanks for the reply, I'd like to do what you suggest, but the script is external and not part of joomal so what do I need to import in order to get access to JURI::base()?

Re: get base url to use in external script

Posted: Thu Jan 15, 2009 10:30 pm
by rfriedel
ademc wrote:Thanks for the reply, I'd like to do what you suggest, but the script is external and not part of joomal so what do I need to import in order to get access to JURI::base()?
If it's not part of the Joomla! framework then you could use the predefined variable $_SERVER
http://us3.php.net/manual/en/reserved.v ... server.php

- or -

You may also be able to use the magic constant __FILE__ like this
http://us3.php.net/manual/en/language.c ... efined.php

Code: Select all

$myPath = dirname(__FILE__);
echo $myPath;
// This will output the absolute path to the CURRENT file excluding the filename
// Also there is NO trailing slash
// This is actually the method that Joomla uses to get the constant JPATH_BASE in the index.php file line 17
Edit: I may have jumped the gun a bit... is the code which you are referring to included at any point in Joomla? If so then you can use the earlier method that I mentioned.

Re: get base url to use in external script

Posted: Thu Jan 15, 2009 10:50 pm
by ademc
The script is included in joomla at some points, but is also accessed directly as well

Re: get base url to use in external script

Posted: Wed Jan 21, 2009 2:13 am
by Big D
I have a module that is also trying to access outside scripts from google. I get an error on my page that says (URL file-access is disabled). Would this method also help me out in accessing outside scripts. I read these posts and followed the recommendations, but I am not sure how to implement. Can someone please explain?

The scripts that my site is trying to access are located at "pagead2.googlesyndication.com/pagead/show_ads.php".

Thanks in advance.

Re: get base url to use in external script

Posted: Tue Feb 10, 2009 10:53 pm
by juicyfruit
Hi,

I would also like to know which file needs to be imported in order to use.

JURI::base()

cheers
Ed

Re: get base url to use in external script

Posted: Tue Oct 13, 2009 11:30 am
by mindphp
juicyfruit wrote:Hi,

I would also like to know which file needs to be imported in order to use.

JURI::base()

cheers
Ed
I would also like to know too.