get base url to use in external script

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
ademc
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Dec 06, 2008 5:53 am

get base url to use in external script

Post by ademc » Thu Jan 15, 2009 10:52 am

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

User avatar
MyJC
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 219
Joined: Fri Aug 19, 2005 2:39 am
Location: Burbank, CA, USA
Contact:

Re: get base url to use in external script

Post by MyJC » Thu Jan 15, 2009 3:43 pm

Code: Select all

baseurl()
"A fool takes no pleasure in understanding, but only in expressing his opinion." Proverbs 18:2

rfriedel
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Fri Jul 11, 2008 8:09 am

Re: get base url to use in external script

Post by rfriedel » Thu Jan 15, 2009 5:53 pm

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
Last edited by rfriedel on Thu Jan 15, 2009 10:37 pm, edited 1 time in total.

ademc
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Dec 06, 2008 5:53 am

Re: get base url to use in external script

Post by ademc » Thu Jan 15, 2009 10:07 pm

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()?

rfriedel
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Fri Jul 11, 2008 8:09 am

Re: get base url to use in external script

Post by rfriedel » Thu Jan 15, 2009 10:30 pm

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.

ademc
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Dec 06, 2008 5:53 am

Re: get base url to use in external script

Post by ademc » Thu Jan 15, 2009 10:50 pm

The script is included in joomla at some points, but is also accessed directly as well

User avatar
Big D
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Mon Feb 25, 2008 3:03 pm

Re: get base url to use in external script

Post by Big D » Wed Jan 21, 2009 2:13 am

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.

juicyfruit
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Mon Jan 16, 2006 10:43 am
Location: Australia
Contact:

Re: get base url to use in external script

Post by juicyfruit » Tue Feb 10, 2009 10:53 pm

Hi,

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

JURI::base()

cheers
Ed

mindphp
Joomla! Guru
Joomla! Guru
Posts: 828
Joined: Thu Mar 15, 2007 6:23 pm
Contact:

Re: get base url to use in external script

Post by mindphp » Tue Oct 13, 2009 11:30 am

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.


Locked

Return to “General Questions/New to Joomla! 1.5”