Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    paris, france
    Posts
    1,216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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']))

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok it worked like this:
    if (isset($_SESSION['logged']) && (isset($_SESSION['logged'])==1))

    thanks

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    paris, france
    Posts
    1,216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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......

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you still redirect them, then what's the point?!
    Offtone.com - In the works...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •