简体   繁体   English

Core Php和CodeIgniter之间的共享会话

[英]Share session between Core Php & CodeIgniter

I have a web app which is in Core PhP . 我有一个Web应用程序,位于Core PhP中 And we are moving it to CI Framework step by step. 我们正在逐步将其移至CI框架

Problem: Need to share session value between them. 问题:需要在它们之间共享会话价值。

Core PHP App Dir Structure: |-- /xampp/lms/ 核心PHP App Dir结构: |-- /xampp/lms/
Core PHP App URL: http://localhost/ lms /index.php 核心PHP应用程序URL: http://localhost/ lms /index.php

CI App Dir Structure: |-- /xampp/lms/newlms/ CI应用程序目录结构: |-- /xampp/lms/newlms/
CI App URL: http://localhost/lms/ newlms /index.php/login CI应用程序URL: http://localhost/lms/ newlms http://localhost/lms/ index.php http://localhost/lms/ /index.php/login

CI Configuration: CI配置:

config.php

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

What I have did so far. 到目前为止,我所做的。

Core PHP changes PHP的核心变化
Path: \\xampp\\htdocs\\lms\\configuration.inc.php ( this is file called first in core php ) 路径: \\xampp\\htdocs\\lms\\configuration.inc.php这是在核心php中名为first的文件

session_name('ci_session');
session_start();

echo '<pre>';
echo '<br/>------------- session_save_path-------- <br/>';
print_r(session_save_path());
echo '<br/>------------- session_name-------- <br/>';
print_r(session_name());
echo '<br/>------------- $_COOKIE -------- <br/>';
print_r($_COOKIE);
echo '<br/>------------- $_SESSION -------- <br/>';
print_r($_SESSION);
exit;  

output: 输出:

------------- session_save_path-------- 
\xampp\tmp
------------- session_name-------- 
ci_session
------------- $_COOKIE -------- 
Array (
    [ci_session] => 2b9tj8rek53kapgsuh4k3v2fuuvblvq9
)

------------- $_SESSION -------- 
Array (
    some values which I have set in Core php
)  

Session Path xampp\\tmp\\sess_2b9tj8rek53kapgsuh4k3v2fuuvblvq9 会话路径xampp\\tmp\\sess_2b9tj8rek53kapgsuh4k3v2fuuvblvq9

CI changes CI变化
path: \\xampp\\htdocs\\lms\\newlms\\application\\modules\\login\\controllers 路径: \\xampp\\htdocs\\lms\\newlms\\application\\modules\\login\\controllers

Class Login extends MX_Controller {

   function __construct() {
     parent::__construct();
   }

   function index() {
echo '<pre>';
echo '<br/>------------- session_save_path-------- <br/>';
print_r(session_save_path());
echo '<br/>------------- session_name-------- <br/>';
print_r(session_name());
echo '<br/>------------- $_COOKIE -------- <br/>';
print_r($_COOKIE);
echo '<br/>------------- $_SESSION -------- <br/>';
print_r($_SESSION);
exit;
   }
 }

output: 输出:

------------- session_save_path-------- 
\xampp\tmp
------------- session_name-------- 
ci_session
------------- $_COOKIE -------- 
Array (
    [ci_session] => 2b9tj8rek53kapgsuh4k3v2fuuvblvq9
)

------------- Core $_SESSION -------- 
Array (
    [__ci_last_regenerate] => 1479978675
)

------------- CI $_SESSION -------- 
CI_Session Object (
 .. Some values.
)

PS: I have tried to explain in best way but Before Down Voting please share the reason. PS:我试图以最好的方式进行解释,但在拒绝投票之前,请分享原因。

As suggested by bertmaclin, 正如bertmaclin所建议的,

CI's session handler is just a wrapper of the php session handler CI的会话处理程序只是php会话处理程序的包装

Have tweek CI's config.php & session Library. 有tweek CI的config.php和会话库。

CI config.php: added given code just before base_url configuration. CI config.php:base_url配置之前添加了给定代码。

session_start();

CI Session.php: added @ before session_start() in session library line #142. CI Session.php:在会话库第142行的session_start()之前添加@。

@session_start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM