Page 1 of 2
Member System
Posted: Thu Feb 26, 2004 5:58 pm
by monkeyj
I just created a member system on my site.. and I need to know how to allow ONLY Logged in ppl to access certain things...
Any start off tips??
Don't know what info you'd need to help.. lol
Umm...
There's a script I saw around.. That looked like it allowed members only...
Code: Select all
<?
session_start();
echo "Welcome ". $_SESSIONї'first_name'] ." ". $_SESSIONї'last_name'] ."! You have made it to the members area!<br /><br />";
echo "Your user level is ". $_SESSIONї'user_level']." which enables you access to the following areas: <br />";
if($_SESSIONї'user_level'] == 0){
echo "- Forums<br />- Chat Room<br />";
}
if($_SESSIONї'user_level'] == 1){
echo "- Forums<br />- Chat Room<br />- Moderator Area<br />";
}
echo "<br /><a href=logout.php>Logout</a>";
?>
But I don't want it Forums/Chat/Moderator or w/e...
I wan't it to be a certain page...
a page saved to my server...
But only accessible if your logged in...
Posted: Thu Feb 26, 2004 6:01 pm
by uberpolak
If you want a whole page to be protected (as opposed to certain elements on the page), you could put it in a folder and set that folder up with
Basic HTTP Authentication. If you don't want to do that you could set an access variable when the user logs in, then do something like this:
Code: Select all
<?php
if ($access == true) {
include('page.php');
} else {
include('noentry.php');
}
?>
Posted: Thu Feb 26, 2004 6:03 pm
by monkeyj
So your saying set the $access to true when they log in.. and put that php on the page I want to protect?
Posted: Thu Feb 26, 2004 6:05 pm
by d3ad1ysp0rk
yup
Posted: Thu Feb 26, 2004 6:07 pm
by monkeyj
What do I put to set the $access?
Posted: Thu Feb 26, 2004 6:08 pm
by d3ad1ysp0rk
I'm thinking you might want to try reading up on some PHP tutorials before you jump into a project like this..
Posted: Thu Feb 26, 2004 6:10 pm
by uberpolak
You need to check if the user and password are correct (since you said you created a member system I'm assuming you know how to do this). So do something like this:
Code: Select all
<?php
if (/*All conditions for access to site are met*/) {
$access = true;
} else {
$access = false;
}
?>
Posted: Thu Feb 26, 2004 6:10 pm
by monkeyj
lol, yea.. But.. I'm so far into it alrdy.. lol
I have everything except the access situation...
o.o
And..
No matter how many times I read php tutorials..
I never understand a bit of the code...
It doesn't make sense to me...
And.. It still doesn't make sense even on the lowest lvls...
Posted: Thu Feb 26, 2004 6:11 pm
by monkeyj
awesome..
Thanks.. I know what to do with that...
Got the verification php file..
Thx Uber.. let me go try it
Posted: Thu Feb 26, 2004 6:12 pm
by monkeyj
Oh and LilSkater...
I don't know the code..
but I know what to do with em.. lol
That's why I feel I can always jump into things.. :p
Posted: Thu Feb 26, 2004 6:19 pm
by tim
i'd personally set a cookie after the log-in, and then on the home page call upon the cookie, if its there, show the page, if not, show the log-in form...
I am happy with that method.
UbErPoLaK
Posted: Thu Feb 26, 2004 6:20 pm
by monkeyj
Now.. This code..
*being the newb non-understanding person he is*
It looks like it still allows access to the "page.php" by manually typing it in...
Or.. Am I not understanding.. Cause..
I want the file/page to totally be blocked unless they're logged in...
Like.. Let's say I want to protect a certain download...
Code: Select all
<?php
if ($access == true) {
include('page.php');
} else {
include('noentry.php');
}
?>
Posted: Thu Feb 26, 2004 6:22 pm
by tim
use the setcookie() method =]
sessions would be way out of your grasp in your early stage of learning..
Posted: Thu Feb 26, 2004 6:22 pm
by monkeyj
ooo.. Tim I like that one.. seems easier

Posted: Thu Feb 26, 2004 6:23 pm
by monkeyj
how do you call a cookie?

I used to know when I read up on em in the past.. but.. thats been like a year ago..