Helpful Information
 
 
Category: PHP
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.

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


//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');" )



session_start();
if (isset $_SESSION['logged'] && $_SESSION['logged'] ==1)
{}
else
{header("location:login.html");}

hope that helps

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']))

ok it worked like this:
if (isset($_SESSION['logged']) && (isset($_SESSION['logged'])==1))

thanks :D

oh yeah. i always screw up my code with these things :p 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).

http://www.webmasterbase.com/article/319

http://hotwired.lycos.com/webmonkey/00/05/index2a.html?tw=programming

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?

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......

If you still redirect them, then what's the point?!










privacy (GDPR)