codeigniter setting session variable with a variable not working

喜夏-厌秋 提交于 2019-12-04 04:44:20

问题


Using codeigniter running locally on WAMP and dealing with sessions. I tried the default session handler, db session, native session and now db session. They all result in the same issue and I can't for the life of me figure it out.

The problem is that I am trying to set a session variable using a variable. I have confirmed the variable and have echoed it out and all is well in the controller. The controller calls on a view and the variable is there as well. The view calls on a uploader file and this is where the variable randomly gets set to "style.css" for some reason. If I set the session statically, say to "randyval", then it sticks. It's only when trying to use a variable that it breaks.

Using db session allows me to set using:

$some_val = $some_otherVal;
$_SESSION['sess'] = $some_val;

Only in the final page does echo $_SESSION['sess'] result in "style.css".

If however I do:

$_SESSION['sess'] = 'test';

Everything works as should.

Wouldn't ask unless I was at my wits ends... thanks for any input.


回答1:


Color me stupid. :\ Turns out there was some bad html that was causing the problem(?). It had to do with, yeah, you guessed it, the header and more specifically where the "style.css" file was being called. Not sure why that was wrecking the session, but it indeed was. So, sorry for wasting everyones time, you can go home now.




回答2:


You should work with CI sessions using Session Class




回答3:


For any of you who stumbled upon this page, see here for the solution : I solved it this way : Losing a session variable between one page with codeigniter session library



来源:https://stackoverflow.com/questions/7775611/codeigniter-setting-session-variable-with-a-variable-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!