How to protect site content

This tutorial will show you how to protect site content by showing different content to logged in users and anonymous site visitors.

The senario I'll use is that you're going to arrange a meet for your site members, but obviously you don't want everyone to know where the event is going to be help. So here's what you do.

Im going to assume you have set yourself up with a login script, I'll be using User Session Pro. If you want to know how to set that up there's a tutorial for adding a members login script to your site here.

First create your html page as your members should see it. That's part is easy yeah, I wont cover how to write html.

So let's say you have this piece of HTML that says where the meet is:

<p>The meet will be at <strong>Fortnox</strong> on the 23rd of June, 19:00. See you there!</p>

All you have to do is wrap that in a php "if" statement and provide some alternative content...like a login box perhaps? So the above code will look like this:

<? if ( $userSessionPro->checkLogin() ){ ?>
<p>The meet will be at <strong>Fortnox</strong> on the 23rd of June, 19:00. See you there!</p>
<? }else{ ?>
<p>Please login to view meet details:</p>
<?=$userSessionPro->showLoginDialog()?>
<? } ?>

You can use the same principle in lots of ways. I hope you find this simple technique to be as useful as I do. You can see the above code in action here:

Please login to view meet details:

Username :
Password :
 
 

If you've got any questions and/or comments about the above tutorial, please do post them here using the form below...or if you prefer email me at info@prophpscripts.com

Name:
*Email:
Comment:
 
*We wont publish your email address, but we will use it to reply to you if you like.
ProPHPScripts