【问题标题】:How to include CKFinder2 to the php page with SESSION security?如何将 CKFinder2 包含到具有 SESSION 安全性的 php 页面中?
【发布时间】:2014-05-10 23:37:31
【问题描述】:

我尝试将CKFinder 包含在我的PHP 网站中。我找到了官方文档:

<?php

$_SESSION['IsAuthorized'] = TRUE; // simple user authorized

$finder = new \CKFinder();
$finder->BasePath = 'http://bow.loc/web/libs/ckfinder2/';
$finder->Create();

但为了让它工作,我需要在 config.php 文件中进行更改:

<?php

session_start();

/**
 * This function must check the user session to be sure that he/she is
 * authorized to upload and access files in the File Browser.
 *
 * @return boolean
 */
function CheckAuthentication()
{
    // WARNING : DO NOT simply return "true". By doing so, you are allowing
    // "anyone" to upload and list the files in your server. You must implement
    // some kind of session validation here. Even something very simple as...

    // return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];
    return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];

    // ... where $_SESSION['IsAuthorized'] is set to "true" as soon as the
    // user logs in your system. To be able to use session variables don't
    // forget to add session_start() at the top of this file.

    return FALSE;
}

// other code...

出于安全原因,我不想简单地使用return TRUE,我想使用SESSION。但问题是我不能这样做,因为$finder-&gt;Create(); 方法返回直接在 IFRAME ckfinder.html 页面中打开的 HTML 代码,所以我的框架中的会话和 CKFinder 中的会话不同,return isset($_SESSION['IsAuthorized']) &amp;&amp; $_SESSION['IsAuthorized']; 返回@ 987654329@!所以我的问题是:

如何将与用户身份验证的会话从我的框架传递到 CKFinder,并在其中为授权用户进行安全验证?非常感谢您的帮助!

【问题讨论】:

  • 了解您使用的框架可能会有所帮助。
  • 你在 config.php 上使用 session_start() 吗?
  • @gabrieloliveira 是的,我在config.php 的顶部添加session_start()
  • 您不能将参数传递给 $finder 对象,其值为 $_SESSION['IsAuthorized'] 并在 CheckAuthentication() 中检查此值?
  • 我真的无能为力。我在这里测试过,效果很好。首先不起作用,因为我用'i'写了 $_SESSION['isAuthorized'],我改变了它并工作,会话是一样的。我检查了您的会话名称,没有什么不同。所以我看不出有什么问题。我也对此进行了测试,这两种方法都有效,但尝试在实例化 $finder 对象之前放置 session_start()。

标签: php session symfony ckfinder


【解决方案1】:

为了安全CKFinder,你需要添加到action:

$this->getRequest()->getSession()->set('AllowCKFinder', TRUE); // Allow to use CKFinder

然后用下面的代码修改CKFinder的config.php文件:

function CheckAuthentication()
{
    session_start();
    $status = FALSE;
    $file = dirname(__FILE__) .'/../../../app/cache/prod/sessions/sess_'. session_id();
    if (file_exists($file)) {
        $status = (bool)preg_match('/AllowCKFinder/i', file_get_contents($file));
    }
    if ( ! $status) {
        $file = dirname(__FILE__) .'/../../../app/cache/dev/sessions/sess_'. session_id();
        if (file_exists($file)) {
            $status = (bool)preg_match('/AllowCKFinder/i', file_get_contents($file));
        }
    }

    return $status;

    // WARNING : DO NOT simply return "true". By doing so, you are allowing
    // "anyone" to upload and list the files in your server. You must implement
    // some kind of session validation here. Even something very simple as...

    // return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];

    // ... where $_SESSION['IsAuthorized'] is set to "true" as soon as the
    // user logs in your system. To be able to use session variables don't
    // forget to add session_start() at the top of this file.

    return false;
}

原帖here

【讨论】:

    猜你喜欢
    • 2014-11-24
    • 2011-06-04
    • 2011-04-13
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 2021-10-10
    • 2015-03-09
    • 2010-11-05
    相关资源
    最近更新 更多