Joomla-取消设置多个会话变量不起作用 [英] Joomla - Unset multiple session variables not working

查看:87
本文介绍了Joomla-取消设置多个会话变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为这很简单,但我想某处有一个陷阱... 我正在为Joomla安装开发代码的自定义部分,并且需要在执行代码之前取消设置一些会话变量.所以,自然地,我有

I thought this would be simple but I guess there's a catch somewhere... I'm developing a custom part of code for a Joomla installation and I need to unset some session variables before executing my code. So, naturally, I have

$session->clear('var1'); 
$session->clear('var2'); 
$session->clear('var3'); 
$session->clear('var4'); 

,但是页面完全空白,没有任何反应.有什么建议吗?

but the page appears totally blank and nothing happens. Any suggestions?

推荐答案

假定您获得了$ session变量,如下所示:

Assuming that you got the $session variable like this:

$session = JFactory::getSession();

如果页面空白,则可能是您的代码中有一些错误.您可以访问某种错误日志吗?如果不是这样,如果不是生产环境,则可以尝试从代码中强制显示错误(尽管这不是最佳选择),或者从joomla管理员启用调试模式.

If you are getting a blank page, you probably some error in your code. Do you have access to some kind of error log? If not, you can try to force displaying errors from your code if it's not a production environment (although it's not the best way to do it) or enable debug mode from the joomla administrator.

您还可以尝试在浏览器中运行php文件,如果一切正常,并且文件中没有解析错误,则您应该会看到类似访问受限"之类的消息.

You can also try to run the php file in your browser, and if everything is ok and there are no parse errors in the file, you should see a message like 'Restricted access' or similar.

此外,如果脚本没有崩溃,您可以检查每次调用$ session-> clear('xxx')会返回什么值(它应该返回刚刚清除的值.

Besides, if the script is not crashing, you can check what value is returning each call to $session->clear( 'xxx' ) (It should return the value you just cleared.

我想到的最后一件事是,您存储在会话中的var在不同的上下文"中.当您将数据获取/设置为会话时,您可以传递名称空间"作为附加参数,因此这些变量存储在该名称空间"中(实际上,它存储在会话中的另一个索引中.因此,如果可能的话,您应该检查这些变量是否使用不同的命名空间"存储在会话中:

The last thing that comes to my mind is that the vars you have stored in session are in a different "context". When you get/set data to session, you can pass a "namespace" as an additional parameter, so these vars are stored in that "namespace" (in fact, it's stored inside another index inside the session. So if possible, you should check if these variables are stored in session using a different "namespace":

$session->set( 'var1', $value, 'another_namespace' );

如果是这样,则应这样清除它:

If so, you should clear it like this:

$session->clear( 'var1', 'another_namespace' );

P.S .:我说名称空间"是因为它是Joomla在这些会话方法中使用的参数名称,但不要与PHP名称空间混淆.

P.S.: I said "namespace" because it's the parameter name that Joomla uses in these session methods, but don't get confused with PHP namespaces.

希望对您有帮助!

这篇关于Joomla-取消设置多个会话变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆