Page 1 of 1

Members and Non-Member Content

Posted: Tue Oct 26, 2004 11:39 pm
by jasemhi
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!

Posted: Wed Oct 27, 2004 12:56 am
by m3mn0n
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.

Posted: Wed Oct 27, 2004 8:24 am
by kettle_drum
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
}

Posted: Wed Oct 27, 2004 9:00 pm
by jasemhi
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.

Code: Select all

<?php
session_start();
session_name('MyPHPSite');
header("Cache-control: private"); // Fix for IE

function login_check()&#123;
    if($_SESSION&#1111;'login'] != TRUE)&#123;
      myheader("Member's Area");
	  $member = 1; // not logged in
      include $_SERVER&#1111;'DOCUMENT_ROOT'].
              '/login_form.html';
      footer();
      exit();
   &#125;
&#125;

?>
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.

Code: Select all

<?php
	include $SERVER&#1111;'DOCUMENT_ROOT'].
	        '/member_box.php';
	switch ($member==1)
	&#123;
	case 1:
	echo 'become a member to create your own kanji list';
	break;

	default:
	include $_SERVER&#1111;'DOCUMENT_ROOT'].
                '/membersonly.php';
	&#125;
	?>
Thanks for your replyies. I hope to hear more form you soon.
Jason

Posted: Thu Oct 28, 2004 1:15 am
by m3mn0n
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)

:)

Posted: Thu Oct 28, 2004 8:07 pm
by jasemhi
Thanks, I read it and worked it out. I now have content for members and non-members!

Jason