我有几个用于AJAX查询的PHP脚本,但我希望它们能够在Joomla的身份验证系统的保护伞下运行。下面的东西安全吗?有没有不必要的线路?
joomla-auth.php (与Joomla的index.php位于同一目录下):
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
/* Make sure we are logged in at all. */
if (JFactory::getUser()->id == 0)
die("Access denied: login required.");
?>test.php:
<?php
include 'joomla-auth.php';
echo 'Logged in as "' . JFactory::getUser()->username . '"';
/* We then proceed to access things only the user
of that name has access to. */
?>发布于 2010-03-15 21:39:18
虽然我在代码中看不到任何不安全的地方,但最好是对标准Joomla组件进行AJAX/JSON调用。这里有一篇关于如何做到这一点的好文章:http://blog.syncleon.com/2009/05/ajax-ify-your-joomla-website.html我也在我的书http://www.packtpub.com/files/learning-joomla-1-5-extension-development-sample-chapter-8-using-javascript-effects.pdf中写过关于JavaScript,Joomla和异步请求的文章(跳到168页)。
本质上,您要做的是为AJAX调用的输出创建一个视图,然后创建一个view.xml.php (或view.json.php)文件而不是view.html.php。当您将&format=xml添加到请求URL的末尾时,它将从view.xml.php而不是view.html.php拉取。
发布于 2012-10-24 03:01:08
当然可以,你需要为用户获取会话数据
jimport( 'joomla.session.session' );
$session =& JFactory::getSession();打印会话以查看输出内容
https://stackoverflow.com/questions/2445549
复制相似问题