PDA

View Full Version : Session Checker, or verifying a logged in member


surf142248
01-18-2006, 09:15 AM
I have been working on a membership system. After a member is logged in, they can go to another 'members only' page, which should only be accessable by members.

Problem: Anyone who types the page address can access the page.

Here is the function code, which I have included at the end of db.php (all the sql database information):

[php]
function session_checker(){
if(!session_is_registered('first')){
include 'login.html';
exit();
}
}
[php]

Now, I theoretically should be able to just put this on top of each page that I designate to be a 'members only' page......right????

[php]
<?
include 'db.php';
session_start();
session_checker();
?>
[php]

So, after I set this up, I should be able to avoid non-registered members just typing the address in to the address bar of the browser to pull that page up.
The problem right now is that it isn't functioning.:confused:

Any assistance with this problem would be greatly appreciated.:D
PS. I am aware of the security problem using first as a session name. I'll worry about it after I get this functional.
Thanks again :)

degsy
01-18-2006, 02:25 PM
try $_SESSION['first'] instead

There are different evaluations


if(!isset($_SESSION['first'])){...

if($_SESSION['first'] == ""){...

surf142248
01-19-2006, 02:52 AM
Thanks Degsy,
I tried implementing your coding suggestion, but no luck.:(
I still am stuck. Users can just type in the address bar the pages I want them to be registered to use, and the pages are viewable. Any other alternatives, educational material, etc. that someone can me to??:confused:

xiaodao
01-19-2006, 03:01 AM
well
when you loggin, after you check the username and password, you should
session_register("first");
$_SESSION['first']="true";

then you on your membership page include

if(!isset($_SESSION['first'])) {
..........
}

surf142248
01-19-2006, 03:41 AM
:confused: :confused: Sorry, I'm not sure if I understand.

The session is registering, on the first members page, or the page you see after you log in.

On that first members page, the session is working.

My problem is that when you try to go to another page that I want only registered users to access, it doesn't work. Instead of denying access, and showing the login screen, it just loads the page as though the user is registered, even though they are not.:confused: :o

Do I really need to register the session again, on every page I want limited to registered users????:confused:

degsy
01-19-2006, 01:40 PM
You need session_start() on every page. Do you have that?