Defining _VALID_MOS to access files from "outside" Joomla

Discuss the development and implementation of Joomla! modules here.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
User avatar
rowanseymour
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sat Feb 04, 2006 5:46 pm
Location: Belfast, Ireland

Defining _VALID_MOS to access files from "outside" Joomla

Post by rowanseymour » Wed Apr 12, 2006 1:25 pm

I've written an AJAX Who's Online module http://forge.joomla.org/sf/sfmain/do/vi ... nline_ajax

The module has a php file which is the AJAX server, which responds to the AJAX requests for updates. When this is happening, _VALID_MOS is not defined because the file isn't being accessed as part of the Joomla application, and this limits what I can access in the way of other Joomla files.

Is it ok to define _VALID_MOS myself and access these files or would that be bad practice? Can I use the Joomla classes such as the database class?

Thanks

lordsiris
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sun Aug 28, 2005 9:30 am

Re: Defining _VALID_MOS to access files from "outside" Joomla

Post by lordsiris » Fri Apr 14, 2006 9:06 pm

I am wondering the same thing...

Anyone have any information?

Thanks...

chris

danuel
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Fri Mar 10, 2006 9:58 pm

Re: Defining _VALID_MOS to access files from "outside" Joomla

Post by danuel » Wed Apr 26, 2006 1:14 am

I am wondering the same thing also.  I will try to help figure it out!

Scarpantibus
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Dec 21, 2005 11:14 am

Re: Defining _VALID_MOS to access files from "outside" Joomla

Post by Scarpantibus » Wed May 31, 2006 10:37 am

I'm having the same problem. I tried to define it myself (using define( '_VALID_MOS', 1 ); at the beginning of the php file), but I still can't use any joomla classes.

any help would be very appreciated.

Scarpantibus.

lordsiris
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sun Aug 28, 2005 9:30 am

Re: Defining _VALID_MOS to access files from "outside" Joomla

Post by lordsiris » Sun Jun 25, 2006 12:59 am

I have done it using the function below... Is there a better way to do this?

Code: Select all

<?php

function getDatabase()
{
	$basePath = dirname( __FILE__ );
	include $basePath . '/../../configuration.php';
	define('_VALID_MOS', '_VALID_MOS');
	include $basePath . '/../../includes/database.php';
	global $database;
	$database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
}

getDatabase();
?>
lordsiris

atpatil11
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Mon Mar 14, 2011 1:25 pm

Re: Defining _VALID_MOS to access files from

Post by atpatil11 » Sat Oct 05, 2013 6:39 am

I know its very old thread but hope will help to other guys so posting my answer.

define( '_JEXEC', 1) or die( 'Restricted access' ); // This will allow to access file outside of joomla.
//defined( '_JEXEC') // Use this if you wanna access file only in Joomla.
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

Just put above lines into your php file & you will be able to access any Joomla classes like database, session n all.


Locked

Return to “Modules”