Member System

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Member System

Post 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?? :D

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&#1111;'first_name'] ." ". $_SESSION&#1111;'last_name'] ."! You have made it to the members area!<br /><br />";

echo "Your user level is ". $_SESSION&#1111;'user_level']." which enables you access to the following areas: <br />";

if($_SESSION&#1111;'user_level'] == 0)&#123;
	echo "- Forums<br />- Chat Room<br />";
&#125;
if($_SESSION&#1111;'user_level'] == 1)&#123;
	echo "- Forums<br />- Chat Room<br />- Moderator Area<br />";
&#125;

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...
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post 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');
}

?>
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post 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?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

yup
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

What do I put to set the $access?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

I'm thinking you might want to try reading up on some PHP tutorials before you jump into a project like this..
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post 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;
}
?>
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post 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...
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

awesome..
Thanks.. I know what to do with that...
Got the verification php file..
Thx Uber.. let me go try it
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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.
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

UbErPoLaK

Post 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'); 
} 

?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

use the setcookie() method =]

sessions would be way out of your grasp in your early stage of learning..
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

ooo.. Tim I like that one.. seems easier :D
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

how do you call a cookie? :P I used to know when I read up on em in the past.. but.. thats been like a year ago..
Post Reply