Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-22-2002, 08:07 PM   PM User | #1
Pompiuses
Regular Coder

 
Join Date: Jun 2002
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Pompiuses is an unknown quantity at this point
Member login problems

I'm making a site where members can log on to certain pages. They must first enter their membernumber and password (which is stored in a mysql database) in a html-form to get acces to these pages. They then get redirected to the pages which is only available to members. The problem is that if someone types the url which the members get redirected to directly into the browser, he can access the member-pages too. How can I check if someone that is using the member-pages has logged in?

I've tried a database lookup on membernumber and password on each page the members enters. The problem is that i'm "loosing" theese values if the member clicks on a link to a different page. Any ideas a appreciated.
Pompiuses is offline   Reply With Quote
Old 06-22-2002, 09:07 PM   PM User | #2
whackaxe
Senior Coder

 
Join Date: Jun 2002
Location: paris, france
Posts: 1,216
Thanks: 0
Thanked 0 Times in 0 Posts
whackaxe is an unknown quantity at this point
ah the wonder of sessions! sesions variables are kept in a folder called sessions on the server and are user to keep track of variables when a user is in your site. they are destoyed when the user quts his browser.

put this code at the end of the login script, just before the script redircts the user to your page
PHP Code:
//please correct me here guy, i alwasys screw somethin up
session_register('logged');
$logged 1// meaning yes of course 
then put this at the beggining of every page you want to protect (or save it in a sepeate and use "require('check.php');" )

PHP Code:
session_start();
if (isset 
$_SESSION['logged'] && $_SESSION['logged'] ==1)
{}
else
{
header("location:login.html");} 
hope that helps
__________________
photoshop too expensive? use the GIMP! www.gimp.org
whackaxe is offline   Reply With Quote
Old 06-22-2002, 09:29 PM   PM User | #3
Pompiuses
Regular Coder

 
Join Date: Jun 2002
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Pompiuses is an unknown quantity at this point
thanks for the tip

but I get a parserror on the part:
$_SESSION['logged'] ==1

i get no parseerror if I remove the '==1' like this:
if (isset($_SESSION['logged']))
Pompiuses is offline   Reply With Quote
Old 06-22-2002, 09:34 PM   PM User | #4
Pompiuses
Regular Coder

 
Join Date: Jun 2002
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Pompiuses is an unknown quantity at this point
ok it worked like this:
if (isset($_SESSION['logged']) && (isset($_SESSION['logged'])==1))

thanks
Pompiuses is offline   Reply With Quote
Old 06-22-2002, 09:41 PM   PM User | #5
whackaxe
Senior Coder

 
Join Date: Jun 2002
Location: paris, france
Posts: 1,216
Thanks: 0
Thanked 0 Times in 0 Posts
whackaxe is an unknown quantity at this point
oh yeah. i always screw up my code with these things as you can see sessions are very usefull and a tip to everybody is get the PHP manual in chm format (help file made with html).
__________________
photoshop too expensive? use the GIMP! www.gimp.org
whackaxe is offline   Reply With Quote
Old 06-22-2002, 10:28 PM   PM User | #6
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,222
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
http://www.webmasterbase.com/article/319

http://hotwired.lycos.com/webmonkey/...tw=programming
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 06-23-2002, 10:32 AM   PM User | #7
Pompiuses
Regular Coder

 
Join Date: Jun 2002
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Pompiuses is an unknown quantity at this point
I get a strange error when handling sessions this way. It seems that you have to log in twice to make it work. The first time you log in you get redirected to the login page again. The second time it all works well. Any ideas why?
Pompiuses is offline   Reply With Quote
Old 06-23-2002, 11:04 AM   PM User | #8
Pompiuses
Regular Coder

 
Join Date: Jun 2002
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Pompiuses is an unknown quantity at this point
ok it works

when I redirect the user to the memberpages after logging in I used 'require'. Then the user had to log in twice. If I use 'header' to redirect it works ok. Strange......
Pompiuses is offline   Reply With Quote
Old 06-23-2002, 11:13 AM   PM User | #9
SYP}{ER
Regular Coder

 
Join Date: Jun 2002
Location: Ontario, Canada
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
SYP}{ER is an unknown quantity at this point
If you still redirect them, then what's the point?!
__________________
Offtone.com - In the works...
SYP}{ER is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:53 PM.


Advertisement
Log in to turn off these ads.