We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

$_SESSION

Development and Programming

angud's avatar
angud
12 posts
15 years ago
angud's avatar angud

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?

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

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.

       
anonymous162744's avatar
anonymous162744
58 posts
15 years ago
anonymous162744's avatar anonymous162744

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.