Jump to content

PHP Sessions


Calgaryalberta

Recommended Posts

I was just curious I have 4 different levels for members on my site. But I have pages that all 4 levels of members can get access too, then I have pages where only members with access levels 3 and 4 can get access too. I was just wondering if anyone knew of a code I could put in the header of each page that checks their if their logged in, and only allows them access to pages that corresponds with their access level.

 

I know its something to do with session_start(), but if anyone knows of any websites that could help me with this, or has any suggestions for a code snippet I could put it, that would be much appreciated! - Thanks

Link to comment
Share on other sites

Yep the login variable is set at 1 I believe, Ill have to confirm it. But yeah I do believe it is set at 1.

So this will work to determine if they are logged in. Thank you very much!! What about a script to add on to this, that checks if they are allowed access to that page or not? Or is that more complex? If you know of any easier way to do this, let me know Im open to suggestions.

 

I just figured it would be allot easier to try and get a script to check weather or not they were allowed access to that page as opposed to creating the page over again for 4 different access levels.

Link to comment
Share on other sites

Personally, I'd suggest creating a tiny user object (either in a session or reading its data from the session), and then query that with the level of the current page.  If the user is not logged in, it could redirect you to a login page, and if they are, it can determine whether to allow the user to view the current page or be given a polite message indicating they can't.  Using a user object means you can keep all your authentication code in one place, which is a generally a good idea.

 

<?php

$level=3;

$_USER=new User();
$_USER->canViewPageLevel($level);

/* only executed if the $_USER->canViewPageLevel method didn't interrupt normal play */

?>

 

That would also make it far easier to automate the authentication process, using an auto_prepend_file or a mod_rewrite to a "base" php script, which could then include other files as needed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.