I'm a newbie but trying to learn.
I have a script to read the joomla user details. It's a simple script just to display logged in user name. The script works if I put it in the root directory of my website.
What I want to do is run the script from a folder off the root, /ssscart, for example.
When I put the script in the sub-directory it does not execute.
Here is my script:
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', '/' );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
JFactory::getApplication('site')->initialise();
$user = JFactory::getUser();
$joomla_name = $user->name;
$joomla_email = $user->email;
$joomla_password = $user->password;
$joomla_username = $user->username;
echo 'hello';
echo " - ".$joomla_username;
?>
I believe my problem is in the JPATH_BASE entry but haven't been able to figure it out yet.
Thanks
G
Try this,
The is issue is due to JPATH_BASE
path getting wrongly.
when you are in root it will look like.
define('JPATH_BASE', dirname(__FILE__) );
So in your case you are in sub folder so it will be look like.
define('JPATH_BASE', dirname(dirname(__FILE__)) );
so your final code will be look like.
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)) );
define( 'DS', '/' );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
JFactory::getApplication('site')->initialise();
Hope it works..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.