Php login Advanced Validations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • friendeyz
    Banned
    New Member
    • Jun 2015
    • 3

    Php login Advanced Validations

    If a user wants to go to profile.php and I assumed that the user is not logged in.
    Now i want to redirect the user to login.php and in the login.php will now echo something like YOU MUST LOGIN TO VIEW THIS PAGE and after the user loged in will take the user to the profile.php which the user requested

    How will i do that stuff and and also after echoing YOU MUST LOGIN TO VIEW THIS PAGE I will want the echoed content to disappear and show only once so that there will be room to echo login errors.
    Can someone Help Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    this is usually done using sessions. you check in the session if the user’s state is loggen in, and if not you redirect him to the login page.

    Comment

    • Bharat383
      New Member
      • Aug 2011
      • 93

      #3
      You can check with session. if the require session is not set on the profile page directly redirect him to login page otherwise if you want to keep him on the profile page, then you can display message there.

      Code:
      <?php
      if(!isset($_SESSION['user_id']))
      {
      echo "You must have to login first.<a href='login.php'>click here to login</a>";
      }
      else
      {
      // code your profile page.
      }
      
      ?>

      Comment

      Working...