How to change a link based on if a user is logged in

Me = busy at 2am!  I searched the world over and couldn’t really find this directly answered, but trial and error won out so I figured out how in php to check the session variable to see if the user is logged in and then if the are change the link.

I have tested it and it works like a charm, the beauty I will tell you up front if you haven’t already moved on from reading this post because it is to ‘techy, geek filled or whatever’ – then the good news is if you don’t have the  <? session_start(); ?> at the top of the page before the html, then the default result is the user gets the NON Logged in link so no worries on if this work!  Now that I got the “Bonus News” out of the way at the beginning, here is all you have to do to make this work!

Hey if you find this doesn’t work please comment, but please DO NOT email me for support!  Put the following at the top of your page, this is assuming you did your handiwork elsewhere to get the user logged in and set the session variable, if you did; whoohoo wait to go!  Again this has to be BEFORE ALL HTML on the page

<? session_start(); ?>

the next little part is what I put in the spot where I want the link to change.

<?
if(isset($_SESSION[‘yourloginvariablename’])== ”) :
echo ‘NOT logged go here <a href=”http://www.site.com/NOT.php”>Click Here</a>’;
else :
echo ‘Logged in go here <a href=”http://www.site.com/LOGGED-IN.php”>Click Here</a><br />’;
endif; ?>

The user will never know and you did a good job making browsing your site easier.  Good for you and good for me, I hope!

Obligatory Will Rogers quotes

Half our life is spent trying to find something to do with the time we have rushed through life trying to save.

There are 3 kinds of people the one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves.

The road to success is dotted with many tempting parking spaces.