Find joomla session variables for php

Asked

Viewed 591 times

1

A client has a site made in joomla, and I have to integrate the login that he does on his site to my site in php. But I don’t know how to get joomla session variables. How can I get them? Or how can I see their name?

  • 1

    $Session = Jfactory::getSession(); echo $Session->get('name'); already tried this ?

  • I tried now but it does nothing

  • You can see how it stores in Session and create a class or Function for access to Session. To see how it stores do: var_dump($_SESSION);die();

3 answers

2

With this code you will get the Joomla session information

<?php
// Recuperando Sessão do usuário Joomla
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
$path = "\\xampp\htdocs\seuprojeto";  //caminho da instalação do Joomla
define('JPATH_BASE', $path);
require_once JPATH_BASE . DS . 'includes' . DS . 'defines.php';
require_once JPATH_BASE . DS . 'includes' . DS . 'framework.php';

$mainframe =& JFactory::getApplication('site');
$db = &JFactory::getDBO();
$mainframe->initialise();
$user =& JFactory::getUser( );


echo $user->id;  //imprime id do usuário
echo $user->name; //imprime nome do usuário
echo $user->password; // Imprime senha do usuário

2

Inside a joomla PHP file, already initialized and preferably logged in (if you work with joomla login), enter the following code:

<pre>
<?PHP print_r($_SESSION); ?>
</pre>

This way you will see all session variables initialized until that moment. To use, just access:

<?PHP echo $_SESSION["nome_da_variavel_mostrada"]; ?>

Remembering that this needs to be put on the site in JOOMLA. In order for you to pass these session variables from your site to your site, it would be interesting if everything was on the same server and domain, for the browser to keep the same session ID.

0

To dump the current Joomla Session just do the following code:

$session = JFactory::getSession();
var_dump($session);

And from this object, you can acquire the information you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.