Hi- I have been working on this for a while but cannot figure this out. What I would like to do is have content for members (logged in users) that is slightly different than the content for non-members (non-logged in users). For example, I would allow members to have their own lists of content where non-members would have generic lists.
How would one go about this? Would I create a variable that shows a user is logged in as a member and then do an if statement that called information for members and an else statement that gives different info for non-members? Or would I send the non-members to a different folder in my site and have them surf around in that where members would surf the members folder?
Please help. I am going crazy staring at my screen and not being able to figure this out.
Thanks!
[SOLVED] Members and Non-Member Content
Moderator: General Moderators
It can be done with a [php_man]switch()[/php_man] conditional. It would be easier to manage the site instead of having two seperate sites for users and anonymous guests. So that's what I recommend doing.
Base the conditional on if the user is logged in. $_SESSION and $_COOKIE both work fine for this.
I also recommend taking a look at some open source apps to see how they have it all setup and coded. That is a good way to learn some more advanced techniques in programming.
Base the conditional on if the user is logged in. $_SESSION and $_COOKIE both work fine for this.
I also recommend taking a look at some open source apps to see how they have it all setup and coded. That is a good way to learn some more advanced techniques in programming.
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Bit of sudo code for your problem:
Code: Select all
-user requests page
if($cookie){
//check to see if the cookie is valid - check with data in database or something
if(valid cookie){
$logged_in = TRUE
}else{
$logged_in = FALSE
}
}else{
//user is guest
$logged_in = FALSE
}
echo page that is the same for all users
if($logged_in){
echo special user only data
}else{
echo guest data
}Let me show you what I have. The following code is called from a session include and if the person isn't logged in they get the login form. If they are logged in they get the members page.
How do I create members only data based on the switch that I have poorly coded? I have read about switch and this is my attempt, but it seems that $member==1 isn't working.
Thanks for your replyies. I hope to hear more form you soon.
Jason
Code: Select all
<?php
session_start();
session_name('MyPHPSite');
header("Cache-control: private"); // Fix for IE
function login_check(){
if($_SESSIONї'login'] != TRUE){
myheader("Member's Area");
$member = 1; // not logged in
include $_SERVERї'DOCUMENT_ROOT'].
'/login_form.html';
footer();
exit();
}
}
?>Code: Select all
<?php
include $SERVERї'DOCUMENT_ROOT'].
'/member_box.php';
switch ($member==1)
{
case 1:
echo 'become a member to create your own kanji list';
break;
default:
include $_SERVERї'DOCUMENT_ROOT'].
'/membersonly.php';
}
?>Jason
What you need to do is add only the variable that you want to work with within the conditional's argument.
It's best explained here: http://php.net/switch (along with some good examples/comparisons)

It's best explained here: http://php.net/switch (along with some good examples/comparisons)