【发布时间】: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->Create(); 方法返回直接在 IFRAME ckfinder.html 页面中打开的 HTML 代码,所以我的框架中的会话和 CKFinder 中的会话不同,return isset($_SESSION['IsAuthorized']) && $_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