A little PHP coding help please

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

CMSB Rocks!



Thanks,



Kurt

By gregThomas - February 22, 2013

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

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

CMSB Rocks!



Thanks,



Kurt