I run into a problem using session in .php file i attached in jumi
How do i set a session in in that page? when i use :
//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();
if(isset($_GET['id'])){
var_dump($id= $_GET['id[i]']);
} else {echo "No session ";}
// code connect to db
// render out the items
//
foreach($rows as $i=>$row){
$id[$i] = $row['rid'];
$name[$i] = $row['rname'];
$view .= '<tr>
<td>'.$id[$i].'</td>
<td>'.$name[$i].'</td>';
?>
}
<p><?php echo $view.'</tr></table>'; ?> </p>
......
It doesn't let me find the sub-page of id=1 that I clicked .
What is the better way to deal with this kind of thing?
thank you.
You have a syntax error try this before you go any further:
</php
//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();
if(isset($_GET['id'])){
var_dump($id= $_GET['id[i]']);
} else {
echo "No session ";
}
// code connect to db
// render out the items
//
foreach($rows as $i=>$row){
$id[$i] = $row['rid'];
$name[$i] = $row['rname'];
$view .= '<tr>
<td>'.$id[$i].'</td>
<td>'.$name[$i].'</td>';
}
?>
<p><?php echo $view.'</tr></table>'; ?></p>
Looking at the way Jumi includes PHP files, you should start with:
defined('_JEXEC') or die('Restricted access');
This will prevent the PHP file from being executed via a direct HTTP request (if you look at the example blogger file included with Jumi you will see this line). The define statements you have, initialise globals that Joomla! code uses to make sure a request has entered through the right path.
Apart from that, as mentioned by #travega you close of the PHP with ?> before you close the foreach()
Related
I've been stuck integrating arrowchat with laravel.
I purchased arrowchat and by install documentation, I did.
But I can't install.
Is it possible to integrate arrowchat to laravel?
I think it's possible.
If possible, how to do that?
To solve this, we should bootstrap Laravel in the integration file of Arrowchat.
So the start of the integration.php should be start like this:
$base_path = dirname(dirname(dirname(dirname(__FILE__))));
require_once($base_path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
require_once($base_path . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . 'autoload.php');
$app = require_once($base_path . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . 'app.php');
try {
$app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();
} catch(\Exception $ex) {
}
function get_user_id() {
$userid = NULL;
global $app;
$app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();
if($app['auth']->user()!= NULL){
$userid = $app['auth']->user()->id;
}
return $userid;
}
Source
Hi I need to display Order Details grid in my Magento FRONT END page. I tried different ways, but nothing worked fine.
Also how to find <?php echo $this->getChildHtml('customer.account.dashboard.extra') ?> block.
Any idea please.
Here is the quick way,
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app()->getStore();
echo '<pre>';
$orders = Mage::getModel('sales/order')->getCollection()
//->addFieldToFilter('status', 'complete')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('status')
->addAttributeToSelect('increment_id')
;
//echo $orders->getSelect();
//exit;
foreach ($orders as $order) {
$email = $order->getCustomerEmail();
echo $order->getIncrementId() . ": '" . $order->getStatus() . "', " . $email . "\n";
}
It fetches all order details. Please comment here if you have any doubt.
We have an application running in Joomla . There is a menu option say 'My Data' - on clicking it will open a php page in an iframe . In this target php we want to capture the current logged in user details where we are facing the problem.
We have used JFactory::getUser() but it is not showing anything . Although if any specific id is passed as parameter to getuser then that id's details are coming . PFB the code . Can someone please help us. Thanks in advance .
/*******Start of code*********/
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
$app = JFactory::getApplication('site');
$app->initialise();
$user =& JFactory::getUser();
echo 'User name: ' . $user->username . '<br />'; echo 'Real name: ' . $user->name . '<br />';
$specificuser =& JFactory::getUser(403);
echo 'Specific User name: ' . $specificuser->username . '<br />'; echo 'Specific Real name: ' . $specificuser->name . '<br />';
/******eof code********/
Instead of this approach which reloads the Joomla framework you could just inspect the session object, this is a dump from Joomla in debug mode:
Session
__default
session.counter ⇒ 13
session.timer.start ⇒ 1363124213
session.timer.last ⇒ 1363162265
session.timer.now ⇒ 1363162286
session.client.browser ⇒ Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
registry ⇒ {}
user
id ⇒ 0
name ⇒
username ⇒
Try using the following:
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );
$mainframe = JFactory::getApplication('site');
$user = JFactory::getUser();
echo 'User name: ' . $user->username . '<br />';
echo 'Real name: ' . $user->name . '<br />';
$specificuser = JFactory::getUser(403);
echo 'Specific User name: ' . $specificuser->username . '<br />';
echo 'Specific Real name: ' . $specificuser->name . '<br />';
Hope this helps
I need to get the information of the user that's currently logged in to Joomla from a program outside of Joomla itself. I upgraded from 1.5 to 2.5, and what I had before doesn't work anymore.
<?php
define( '_VALID_MOS', 1 );
include_once( 'globals.php' );
require_once( 'configuration.php' );
require_once( 'includes/joomla.php' );
$option="test";
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();
$my = $mainframe->getUser();
$joomla_name = $my->name;
$joomla_email = $my->email;
$joomla_password = $my->password;
After some research, I've come up with this:
<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', dirname(__FILE__) );
define( 'DS', '/' );
require_once ( JPATH_BASE .DS.'configuration.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$my =& JFactory::getUser();
$joomla_name = $my->name;
$joomla_email = $my->email;
$joomla_password = $my->password;
$joomla_username = $my->username;
It doesn't produce any errors but seems to work. However, the user object is empty. This script is in the same directory as the Joomla installation. What may be the problem? Thanks!
Sources:
http://www.cmsbloke.com/accessing-joomla-objects-from-an-external-script/
Taken from
http://docs.joomla.org/How_to_access_session_variables_set_by_an_external_script
Solution: Replace session_start(); in your external script with
define( '_JEXEC', 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' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
Be sure to change JPATH_BASE to suit your directory structure.
Replace the $_SESSION[ 'name' ] = "value"; in your external script with
$session =& JFactory::getSession();
$session->set('name', "value");
Now you can retrieve this session variable using:
$session =& JFactory::getSession();
echo $session->get('name');
It turns out, I had two problems:
My script was on www.example.com, while I was logged in under example.com, so the different domain was throwing off the session data.
I also wasn't initialising the application, which apparently is necessary.
Here are the results:
<?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;
I think people have had problems with this in Joomla 2.5 as things have changed. I haven't found a solution for the way you have requested but wrote this work around (excluding the password field though) that you may want to use.
define a connection to the database:
<?php
$host="localhost";
$username="DB_USERNAME";
$password="DB_PASSWORD";
$db_name="DB_NAME";
mysql_connect($host,$username,$password)or die(mysql_error());
mysql_select_db($db_name)or die(mysql_error());
?>
Echo create a query and echo the results in a table:
<table style="background:#FFF; color:#000;">
<?php
$query = "SELECT username,name,email FROM j25_users ";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo '<tr><td>',$row["username"],'</td><td>',$row["name"],'</td><td>',$row["email"],'</td></tr>' ;
}
?>
</table>
You will need to change j25_users to the correct prefix of your database tables.
Update: Much better to import the framework to get the user object.
Hope this comes in handy for you. Regards.
If you want to skip using Joomla! functions, you can query the Joomla! database. Join tables js25_session and js25_users with the user id. This way, you can get every currently logged-in user and all guests on the website (and possibly the number of online users).
I have a joomla Website. I have also installed a wordpress in the root folder of my joomla website. ie joomla/wordpress . I am not able to get the session value set in joomla in wordpress. How do i get the session value set in joomla in wordpress and vice versa.
Joomla has its own session handling, so the only way is to use the Joomla functions like this:
define( '_JEXEC', true );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
To get Joomla user id:
$user =& JFactory::getUser();
$user_id = $user->get('id');
and to get user session id use:
$session = & JFactory::getSession();
$session_id = $session->getId();