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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Passing value trough a 3rd page?

    Good day,
    I was looking on the web and I can't find what I'm looking for or I don't really understand.

    Let take the example of the login script.

    The user enter his user ID and password and then if it match redirect to another page. Now, when he click on a link he would then go to that page, how can I verify is user id and password again on the 3rd page and so on ?

    I know it's something easy but I'm don't understand this.

    Thanks !

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    $_SESSION is what you would use.
    Leonard Whistler

  • #3
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Just to expand on what Len said -

    You'd use php sessions to track whether the user has logged in. At the top of each of your php pages you'll need:
    PHP Code:
    session_start(); 
    When you verify a successful log-in, set the session variable:
    PHP Code:
    $_SESSION['loggedin'] = true
    Then, for access to each page, you can check if the user has logged in:
    PHP Code:
    If (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true)
    {
       
    // allow user to access page
    }
    else
    {
      
    // redirect to login page

    If you need the user id for each page, you can set that when you verify the log-in:
    PHP Code:
    $_SESSION['userid'] = $user_id

  • #4
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    And what if I want multiple user but I can't use db ?

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Thanks for the explanation and code !

  • #6
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    You're welcome.

    If you need to store multiple users and don't have access to a db, you can use a text file. For security the text file should be outside of your document root, and of course, store a hash of the password and not the actual password.


  •  

    Posting Permissions

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