$CURRENT_USER is not working properly.

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 13, 2015   (RSS)

By Mikey - October 12, 2015

I've got a page where I'm trying to load in the current user's fullness, email and phone number stored in their profile. But nothing I do seems to work and $CURRENT_USER works in reverse as well.

For example - the line of code below is presently seen by users who are logged out, but notice the bold ! which should do exactly the opposite from my understanding.

<?php if (!$CURRENT_USER): ?>
<h3 style="margin-top:24px;">USER Logged In</h3>

... AND the line of code below is seen by those who are logged in

<?php if ($CURRENT_USER): ?>
<h3 style="margin-top:24px;">Guest</h3>

I'm trying to pre-populate three of the fields with the logged in "USER" profile data entries using the code below, and no matter which setting I apply above, no data gets plugged into the fields.

<input name="registrant_name" value="<?php echo $CURRENT_USER['fullname'] ?>" size="24"><div>Name</div>
<input name="registrant_email" value="<?php echo $CURRENT_USER['email'] ?>" size="24"><div>Email</div>
<input name="registrant_phone" value="<?php echo $CURRENT_USER['phone'] ?>" size="24"><div>Phone</div>

The code I'm using works perfectly in CMS Builder V2.61, but does seem to work in CMS Builder V2.65.

Hey Zicky, 

The following code isn't displaying for users who are logged in, as you've got a not operator in it:

<?php if (!$CURRENT_USER): ?><h3 style="margin-top:24px;">USER Logged In</h3>

If you remove that, the code should only display for users who are logged in:

<?php if ($CURRENT_USER): ?><h3 style="margin-top:24px;">USER Logged In</h3>

With this line of code:

<?php if ($CURRENT_USER): ?><h3 style="margin-top:24px;">Guest</h3>

Do you want to only appear for users who are logged out? If so, you need to add the following:

<?php if (!$CURRENT_USER): ?><h3 style="margin-top:24px;">Guest</h3>

For these fields:

<input name="registrant_name" value="<?php echo $CURRENT_USER['fullname'] ?>" size="24"><div>Name</div>
<input name="registrant_email" value="<?php echo $CURRENT_USER['email'] ?>" size="24"><div>Email</div>
<input name="registrant_phone" value="<?php echo $CURRENT_USER['phone'] ?>" size="24"><div>Phone</div>

Could you give me the code for the entire page? I'm not sure why they're not displaying at the moment. 

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Thanks Zick,

I think I've worked out what the issue is; the server doesn't allow sharing of cookies between HTTP and HTTPS. 

If you look through your phpinfo and search for session.cookie_secure, you'll see that this option is enabled locally.

I'd contact your host and ask them if they can disable session.cookie_secure, then you'll be able to use the current_user variable on both protocols.

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com