Reply
Restricting pages to authorised users
Old 05-18-2007, 04:49 AM Restricting pages to authorised users
Novice Talker

Posts: 7
Name: Brian
I'm building a site where all pages need to be publicly viewable except for URLs starting with '/my-account'. So, '/my-account/change-password' etc. would only be allowed to be viewed by people who have logged in.

Information:
1. I'm using PHP sessions
2. My URLs get rewritten: '/my-account/change-password' would be rewritten to something like /changepassword.php
3. If a user logs in, $_SESSION['auth'] gets assigned the value of '1'

I'm wondering what the best way to go about this is; I could just go:
if ($_SESSION['auth'] != 1) /*display login*/
else { /*display the authorised page*/ }

That would be a bit irritating to type in for each page. Is there possibly a better way to do it?

Thanks
oldforkbeard is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-18-2007, 07:04 AM Re: Restricting pages to authorised users
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
make a function for the check login part
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 05-21-2007, 10:55 AM Re: Restricting pages to authorised users
Novice Talker

Posts: 6
You could put all you session code in one file and include it in every page so if you need to change it in the future it will be easy.
__________________
lpcwebdesign.com
lpc101 is offline
Reply With Quote
View Public Profile
 
Old 05-21-2007, 10:58 AM Re: Restricting pages to authorised users
Junior Talker

Posts: 3
Name: James
you could include your login script in each page you want restricted.
So make a file called access_control.php or like that, and start with
if (!$_SESSION['auth']) /*display login*/
else { /*display the authorised page*/ }

have it act on SELF
Durinthiam is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Restricting pages to authorised users
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12474 seconds with 13 queries