A little PHP coding help please
4 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: February 22, 2013 (RSS)
By kkegans - February 22, 2013
I am using the Membership plugin foir the first time and I am not fluent in PHP. I am attempting to display a different set of navigation links to logged in users an non-logged in users. This is the code I have on the site now:
<div id="header">
<?php include 'include/header_inc.php' ?>
<?php if ($CURRENT_USER): ?>
<?php include 'include/member_navigation_inc.php' ?>
<?php else: ?>
<?php include 'include/navigation_inc.php' ?>
<?php endif ?>
The problem is, if the usere is logged on, both navigation includes are being displayed in the same space. I am sure it is a problem with this code, and could sure use some input to assist me here.
Thanks!
Kurt
Thanks,
Kurt
By Dave - February 22, 2013
Hi Kurt,
Your code looks good. What is displayed when you "View Source" in the browser?
Sometimes when I'm working on something I start simple (even now) to make sure things are working, like this:
<?php if ($CURRENT_USER): ?>
Current User is logged in.
<?php else: ?>
No one is logged in.
<?php endif ?>
Let me know if that works and what "view-source" shows (does it show the includes you expected, PHP code, errors, or something else?
Hope that helps!
interactivetools.com
Hi Kurt,
The code looks good to me, the only change I would suggest is adding an @ to $CURRENT_USER to stop it displaying an error if no one is logged in:
<?php include 'include/header_inc.php' ?>
<?php if (@$CURRENT_USER): ?>
<?php include 'include/member_navigation_inc.php' ?>
<?php else: ?>
<?php include 'include/navigation_inc.php' ?
<?php endif ?>
I would check that your not accidentally including navigation_inc.php below the if statement, or that it isn't being included in member_navigation_inc.php.
If neither of these are the issue could you attach the three files to a post so I can take a look at your code?
Thanks!
Greg
PHP Programmer - interactivetools.com
By kkegans - February 22, 2013
Dave,
Thanks for the tip...it makes a lot of sense.
I don't know what was going on but I tried your example and everything worked as expected, then reloaded my original code and it worked as expected.
Thanks again,
Kurt
Thanks,
Kurt