Hello,
I am encountering php errors when I try to add $_SESSION code to expressionengine. I have read a few forum topics and none have helped. I am a designer and this is code the developer told me to input into the CMS, but it keeps throwing errors. Other php statements work fine, like simple echos, etc. Any help would be greatly appreciated.
At the top of my “head” include I added the code:
<?php session_start(); ?>I then try to include the following code in my template and it throws errors:
<?php
if ( $_SESSION['UserID'] == "" ) {
echo 'User Not Logged in';
} else {
echo 'User Logged in';
}
?>I have ensured that I logged in (multiple times) to set the session. My developer ensures me that it is being set because he is developing outside of EE and he’s not having any errors. The errors that are thrown are below taken from my source code:
Can anybody help?
Why are you using $_SESSION to check if the user is logged in or not?
See Conditional Global Variables
in PHP, the key needs to be set before it’s checked
eg:
<?php
if (isset($_SESSION['UserId']))
{
// logged in
}But I would still use the logged_in global instead.
Hello,
This doesn’t work for me because I need to test a SESSION variable that developers are using in a different part of the site not associated with EE.
The flow of the site will be a client logging into the “developers section” of the site, and when they return to the EE part (it’s all under the same domain, just different folders), then I need to present logged in users with certain info to access their members area.
I can’t use EE’s conditional variables because the session is being created outside EE and EE has no inherent knowledge of it.
Please advise.
Thank you.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.