Session Management in Joomla!

Well, at least it’s 1st time i wrote on joomla! a framework based PHP that very2 prety in structure and have a lot of functionality.
Some of you maybe a joomla! developer and try to get a joomla session and put in another php file.
You can’t just put session_start() and get $_SESSION[] data. Joomla’s default session is saved on #__session table. so you need to reset back session save handler to file (or another , as we know, default session save handler in PHP is file mean session data is saved in file). Just put this code on joomla’s Component/module/plugin than session need to exported

$temp_session = $_SESSION; // backup all session data
session_write_close();
ini_set(“session.save_handler”,”files”); // set session saved hadler on file
session_start();
$_SESSION["user"]= “I’m user”; // data that another php file need to know
session_write_close();
ini_set(“session.save_handler”,”user”); // put back session saved handler on database
$jd = new JSessionStorageDatabase();
$jd->register(); // set required parameters
session_start(); // restart //
$_SESSION = $temp_session; // restore last session data

of course you need to get session id that another php file must know. You can save it on cookie or pass it as parameter on new php file.

$e = session_id();
setcookie(“jsid”, $e, time()+3600,’/');

nah .. in another php file you just need to set session_id and can start session
if($_COOKIE["jsid"]!=”"){
session_id($_COOKIE["jsid"]);
}
session_start();
var_dump($_SESSION["user"]);
so you can see new session displayed there. Of course it just display session in files and session that saved in database can’t be shown

9 comments so far

  1. riza on

    opo iki wa

  2. pribadidewa on

    ada deh :) ..

  3. Nur Aini Rakhmawati on

    sleeping session now :)

  4. pribadidewa on

    waduh, suatu kehormatan besar nih , suhu joomla! kelas dunia mau komentar disini .. bikin ngantuk ya mbak artikelku :D .. ntar insya Allah nanti nulis yang lebih bagus lagi

  5. Irfander on

    Mas tolonglah aku yang desperate ini :) .

    Saya pake login joomla trus di redirect ke sebuah halaman tersendiri. kalo redirectnya bisa, tapi gimana ngambil variabel session sehingga data user yang barusan login itu terbaca di halaman tersendiri.

    Mohon panduannya, terima kasih

    coba ikuti management session seperti di atas .. insya Allah bisa koq.. untuk mengetahui data user mana yang disimpan , coba pake perintah var_dump($_SESSION)

  6. demiss on

    That’s a good one. i’m also trying to use session variable in joomla frame work but your idea is a bit wider than i antisipated. do you know simpler methode to pass session variable from one file to other?

    i think this is the minimum requirement needed. isn’t it easy ?. the ONLY WAY we can do is change joomla! way to save session then put it back ..

  7. foil on

    bisa minta tolong dijelasin dlm bhs indo?

    trus yg bagian ini maksudnya ditaruh dimana ya:
    of course you need to get session id that another php file must know. You can save it on cookie or pass it as parameter on new php file.
    $e = session_id();
    setcookie(”jsid”, $e, time()+3600,’/’);

    bisa minta tolong gak misalnya pingin ngambil session username dari joomla trus username itu akan dipakai di php diluar joomla? script2 diatas diletakkan dimana aja ya?
    thanks bantuannya

  8. Wlad on

    friend, in which file should I put the code?

  9. Sam on

    where would i have to paste this code in order to get session details!


Leave a reply