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


opo iki wa
ada deh
..
sleeping session now
waduh, suatu kehormatan besar nih , suhu joomla! kelas dunia mau komentar disini .. bikin ngantuk ya mbak artikelku
.. ntar insya Allah nanti nulis yang lebih bagus lagi
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)
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 ..
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
friend, in which file should I put the code?
where would i have to paste this code in order to get session details!
Thank you for the great tip! After some fiddling, and more reading, I finally got this to work.
I’ve seen several solutions that involve accessing Joomla mainframe within an external script. HOWEVER there are scripts that bomb if you try this (such as the standalone script I’m currently bridging to Joomla).
First, you MUST have Session Handling set to Database (see your Joomla Global Configuration). This is usually the default upon installation, unless you changed it at some point.
Just as the instructions above show, you have to put the sesssion creation code in your Joomla plugin or component (or a file that your plugin or component includes, in my case).
THEN, you put the code that calls the session in your external script (the one that needs to get the data).
What ISN’T well documented (I had to dig for it) is that, for this to work, each and every page of your script must call the session this way. You should have a central file (such as a header.php for example) that is called every time a page is rendered. THAT is where the session call goes.
EXAMPLE:
Joomla myPlugin -> create session
My Script’s header.php file -> calls the session
Now, every page in my script calls the header.php file, so every page in my script calls the session correctly. Keep this in mind when, say, you’re updating existing session variables – you gotta make sure you call that session correctly.
mas … saya bingung dengan artikel nya , bisa tidak dijelaskan step by step disertai contoh langsung
… harap maklum newbie …. thnks b 4
Thank you, you saved me another 2 hours!
Nice post. I learn some factor tougher on distinct blogs everyday. Most commonly it is stimulating to find out to read content by other writers and exercise a specific thing there. I’d would rather use some together with the content in my weblog no matter whether you don’t mind. Natually I’ll provide you that has a link in your net weblog. Many thanks for expressing.