[Workaround found] CodeIgniter 3.0 cannot access native $_SESSION |
04-14-2015, 06:00 AM
(This post was last modified: 04-14-2015, 05:32 PM by gofrendi. Edit Reason: Find Solution )
Hi, I'm using CodeIgniter 3.0.
CI 3's session can also be accessed as $_SESSION. However this $_SESSION is quiet different from PHP's native $_SESSION. Let's say I have a controller like this: PHP Code: <?php It will yield this: array (size=1) '__ci_last_regenerate' => int 1429015988 However, when I make another file in FCPATH THIS IS NOT A CONTROLLER/VIEW/MODEL, JUST A PHP FILE WHICH IS CALLED DIRECTLY PHP Code: <?php It yield this: array (size=0) empty This make CodeIgniter cannot share session with external application. Is it an expected behavior? Is there any workaround if I want to share codeigniter's session with external php script? UPDATE: Here is my ugly-but-work workaround: CodeIgniter can't access native session, but external PHP can access CodeIgniter's session like this: PHP Code: ob_start(); This works, but it is actually awkward. When you include "index.php", it will also do all the process in your default controller's. However this is the easiest and best way I can find. Other solution (including decode the cookie) will be very hard. |
Welcome Guest, Not a member yet? Register Sign In |