A little PHP coding help please

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

CMSB Rocks!
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!

Dave Edis - Senior Developer
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

Greg Thomas







PHP Programmer - interactivetools.com