Php Codeigniter 3-从Codeigniter安装外部访问会话

Php Codeigniter 3-从Codeigniter安装外部访问会话,php,codeigniter,session,Php,Codeigniter,Session,我似乎无法将会话数据从codeigniter应用程序传回includes文件夹中的脚本。根据我在其他答案上读到的内容,我需要设置我的session\u id(),以便能够使用session\u start()重新加入会话 我是不是误会了会议?我发现这可能对你以后的工作有所帮助 <?php ob_start(); include('index.php'); ob_end_clean(); $CI =& get_instance(); $CI-&

我似乎无法将会话数据从codeigniter应用程序传回includes文件夹中的脚本。根据我在其他答案上读到的内容,我需要设置我的
session\u id()
,以便能够使用
session\u start()
重新加入会话

我是不是误会了会议?

我发现这可能对你以后的工作有所帮助

<?php
    ob_start();
    include('index.php');
    ob_end_clean();
    $CI =& get_instance();
    $CI->load->library('session'); //if it's not autoloaded in your CI setup
    echo $CI->session->userdata('name');
?>

来自@wolfgang1983的原始答案与此处的答案相结合:来自

您可以从任何目录中包含
index.php
,但是,您需要更改
$system\u path
$application\u文件夹
变量以匹配您的相对位置。如果您想完全更改整个应用程序的路径,那就太好了,但我不想这样做,所以我只是将
index.php
文件复制到我需要包含codeigniter的目录中

ROOT /
     .. /application
     .. /system
     .. /includes
        .. /Events.php <- I need access from here
        .. /index.php <- Copied CI index with new paths
     .. /index.php
现在,您可以在文件中包含codeigniter,包括:

<?php
    ob_start();
    include('index.php');
    ob_end_clean();
    $CI =& get_instance();
    $CI->load->library('session'); //if it's not autoloaded in your CI setup
    echo $CI->session->userdata('name');
?>

改进@acupajoe的答案,您不必复制粘贴CI
index.php
。将
包含部分改为:

<?php
    ob_start();
    define("REQUEST", "external");
    $temp_system_path = 'path/to/system/folder/from/external/file';
    $temp_application_folder = 'path/to/application/folder/from/external/file';
    include('path/to/index.php/file/from/external/file');
    ob_end_clean();
    $CI =& get_instance();
    //...
?>


为这个答案脱帽致敬。真正地避免了很多关于为什么AJAX请求加载我们应用程序的登录屏幕HTML的困惑@保罗·斯金纳很高兴我能帮上忙!对于那些希望使用CI作为后端框架的人来说,这是最好的解决方案:)。像我一样,我需要使用wordpress作为我的前端,我需要一个硬代码来添加一个新的登录仪表板,这将发生。最好的答案。对于CodeIgniter版本3.1.9仍然有效
define(“请求”、“外部”)可能存在重复的竖起拇指。如果你的
index.php
总是重定向到其他页面,那么添加这一行,你的站点将不会重定向到其他页面。干得好。。。爱你
//$system_path = 'system';
$system_path = '../system';

//$application_folder = 'application';
$application_folder = '../application';
<?php
    ob_start();
    include('index.php');
    ob_end_clean();
    $CI =& get_instance();
    $CI->load->library('session'); //if it's not autoloaded in your CI setup
    echo $CI->session->userdata('name');
?>
ob_start();
define("REQUEST", "external"); <--
include('index.php');
ob_end_clean();
function index()
{
    if (REQUEST == "external") {
        return;
    } 

    //other code for normal requests.
}
<?php
    ob_start();
    define("REQUEST", "external");
    $temp_system_path = 'path/to/system/folder/from/external/file';
    $temp_application_folder = 'path/to/application/folder/from/external/file';
    include('path/to/index.php/file/from/external/file');
    ob_end_clean();
    $CI =& get_instance();
    //...
?>
$system_path = isset($temp_system_path) ? $temp_system_path : 'system';
$application_folder = isset($temp_application_folder) ? $temp_application_folder : 'application';