Access CodeIgniter session values from external files

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
//path to your database.php file
require_once("../frontend/config/database.php");
$cisess_cookie = $_COOKIE['ci_session'];
$cisess_cookie = stripslashes($cisess_cookie);
$cisess_cookie = unserialize($cisess_cookie);
$cisess_session_id = $cisess_cookie['session_id'];
$cisess_connect = mysql_connect($db['default']['hostname'], $db['default']['username'], $db['default']['password']);
if (!$cisess_connect) {
die("<div class=\"error\">" . mysql_error() . "</div>");
}
$cisess_query = "SELECT user_data FROM ci_sessions WHERE session_id = '$cisess_session_id'";
mysql_select_db($db['default']['database'], $cisess_connect);
$cisess_result = mysql_query($cisess_query, $cisess_connect);
if (!$cisess_result) {
die("Invalid Query");
}
$cisess_row = mysql_fetch_assoc($cisess_result);
$cisess_data = unserialize($cisess_row['user_data']);
// print all session values
print_r($cisess_data);
<?php //path to your database.php file require_once("../frontend/config/database.php"); $cisess_cookie = $_COOKIE['ci_session']; $cisess_cookie = stripslashes($cisess_cookie); $cisess_cookie = unserialize($cisess_cookie); $cisess_session_id = $cisess_cookie['session_id']; $cisess_connect = mysql_connect($db['default']['hostname'], $db['default']['username'], $db['default']['password']); if (!$cisess_connect) { die("<div class=\"error\">" . mysql_error() . "</div>"); } $cisess_query = "SELECT user_data FROM ci_sessions WHERE session_id = '$cisess_session_id'"; mysql_select_db($db['default']['database'], $cisess_connect); $cisess_result = mysql_query($cisess_query, $cisess_connect); if (!$cisess_result) { die("Invalid Query"); } $cisess_row = mysql_fetch_assoc($cisess_result); $cisess_data = unserialize($cisess_row['user_data']); // print all session values print_r($cisess_data);
<?php
//path to your database.php file   
require_once("../frontend/config/database.php");
$cisess_cookie = $_COOKIE['ci_session'];
$cisess_cookie = stripslashes($cisess_cookie);
$cisess_cookie = unserialize($cisess_cookie);
$cisess_session_id = $cisess_cookie['session_id'];
$cisess_connect = mysql_connect($db['default']['hostname'], $db['default']['username'], $db['default']['password']);
if (!$cisess_connect) {
    die("<div class=\"error\">" . mysql_error() . "</div>");
}
$cisess_query = "SELECT user_data FROM ci_sessions WHERE session_id = '$cisess_session_id'";
mysql_select_db($db['default']['database'], $cisess_connect);
$cisess_result = mysql_query($cisess_query, $cisess_connect);
if (!$cisess_result) {
    die("Invalid Query");
}
$cisess_row = mysql_fetch_assoc($cisess_result);
$cisess_data = unserialize($cisess_row['user_data']);
// print all session values 
print_r($cisess_data);