I have developed a website in codeigniter and integrated wordpress for blog. My problem is if i logged in the site, i am not able to use the codeigniter session value in the wordpress blog.
In Codeigniter once i logged in i am setting the following session using codeigniter session.
$this->session->set_userdata('get_user_session', $auD);
Now i need to use the session in wordpress header file or index file. I tried the below code in wordpress.
session_start();
print_r($_SESSION);
I am not getting the above ci session values.
CodeIgniter's Session class:
>> stores session information for each user as serialized (and optionally encrypted) data in a cookie
.
The values you set using $this->session->set_userdata('key','value')
are not going to be present in the $_SESSION
variable.
CodeIgniter also supports storing session content in a database.
You can use that configuration to retrieve the session data in your WordPress blog.
Use COOKIES to get the session data.
Refer this link: https://thomashunter.name/blog/accessing-codeigniter-session-data-using-external-scripts/
require_once("config.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(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_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' LIMIT 1";
mysql_select_db(MYSQL_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_r($cisess_data);