thelberg Posted September 21, 2007 Share Posted September 21, 2007 Hi, I'm realy a newbie in PHP programming. (Using Dreamweaver for basic operations.) Now I need to create a site where users who are logged in can get access to additional contents, compared to anonymus users who are NOT logged inn. Example: On a public website with information about shoes, anyone can see the pictures and description. What I want is when a salesperson or administrator in my companys staff is logged in, he/she will be able to see some more information - about prices and stuff.. In .ASP the command for this is <% if (Session("MM_UserAuthorization")) = "Administrator" then %> {Enter the additional stuff here... Text, tables, pictures, buttons...} <% end if %> Anyone know the similar code for .PHP? ??? Quote Link to comment https://forums.phpfreaks.com/topic/70122-solved-how-do-i-use-login-session-to-show-spesific-areas-when-logged-in/ Share on other sites More sharing options...
Irksome Posted September 21, 2007 Share Posted September 21, 2007 This is what I have for my member section, more or less the same as what you're asking but you'll need to customise it to your needs. <?php session_start(); // If users aren't logged in then display error message and exit. if($_SESSION['user_level'] == 0){ echo "You do not have access to this section. Please log in first.";exit; } // Users logged in successfully, display options. echo "Welcome ". $_SESSION['username'] ."!<br /><br />"; echo "Member Options"; echo "Member Option 1"; echo "Member Option 2"; echo "Member Option 3"; // Special options for admins and developers. if($_SESSION['user_level'] == admin){ include "admin/adminoptions.php"; } if($_SESSION['user_level'] == dev){ include "admin/devoptions.php"; } echo "<a href=logout.php>Logout</a>"; ?> This is assuming you already have a login script set up, as this requires sessions from the login script. Just change them to suit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/70122-solved-how-do-i-use-login-session-to-show-spesific-areas-when-logged-in/#findComment-352193 Share on other sites More sharing options...
thelberg Posted September 21, 2007 Author Share Posted September 21, 2007 Thanks, just what I needed It worked well; both the section with "Member options" displayed, and including different files depending on wich level you are logged in. But; When an anonymus user NOT are logged in... That's difficult... I can't get that right... Here's my code based on my own loginprosedure: <?php session_start(); // If users aren't logged in then display this message. if($_SESSION['MM_UserGroup'] == 0){ echo "You are not logged in."; } // Users logged in successfully, display options. echo $_SESSION['MM_Username'] ."</b><br /><br />"; ?> "...UserGroup'] == 0..." I don't have any usergrups with level 0. Is there any way of telling the session that no one has logged on? I can't put thousands of anonymius users in their own usergroup?? My point is, anonymus users will see some information, like including a file containing a recordset with some fields visible. When a registerd user log in, he or she will see more information! From another file containing the same recordset, but with some more fields visible now. Your describtion solve this partialy. However, the missing link here is how to include one spesific file when nobody is logged in, and another file when somebody is logged in. Quote Link to comment https://forums.phpfreaks.com/topic/70122-solved-how-do-i-use-login-session-to-show-spesific-areas-when-logged-in/#findComment-352259 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 Give this Login tutorial a try... Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70122-solved-how-do-i-use-login-session-to-show-spesific-areas-when-logged-in/#findComment-352260 Share on other sites More sharing options...
thelberg Posted September 21, 2007 Author Share Posted September 21, 2007 Great! Think I got it now :) Little to soon to set this problem as "Solved" yet. I'll give it some more try over the weekend. Thanks to both of you Quote Link to comment https://forums.phpfreaks.com/topic/70122-solved-how-do-i-use-login-session-to-show-spesific-areas-when-logged-in/#findComment-352285 Share on other sites More sharing options...
AdRock Posted September 21, 2007 Share Posted September 21, 2007 You can use this tutorial also http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/1/ On the page you want to protect from unregistered users you could use something like this <?php if (!is_authed()) //function to check if user logged in { print ('You need to login to view this page, <a href="/login">click here</a> to login.'); include('login.php'); } else { //display the page content } ?> function to check if use logged in <?php function is_authed() { if (isset($_SESSION['username'])) { return true; } else { return false; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70122-solved-how-do-i-use-login-session-to-show-spesific-areas-when-logged-in/#findComment-352293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.