Check whether user is logged in or not

12,985

Solution 1

Your question is very vague - maybe start with Authentication in PHP

Solution 2

You could store a value in the Session called "Login" and set this when the user logs in. This can also be used to re-direct the user if they haven't been logged in:

<?php

  // check that the session variable does exist
  // check that the user 'LoggedIn' has been set to 1 (true)
  if (!isset($_SESSION['LoggedIn']) && $_SESSION['LoggedIn'] != 1)
  {
       // redirect to login page for user to authenticate themselves.
       // pass page location (with parameters if necessary) to redirect
       // the user on successful login.
       header("Location: Login.php?redir=ApplyForJob.php?JobID=12345");
  }
  else
  {
       // user is logged in
       // redirect the user directly to the apply for job page.
       header("Location: ApplyForJob.php?JobID=12345");
  }

?>

Solution 3

Well, when the user clicks on 'apply' in your application the user is redirected to the login page if he is not logged in(which you can check if user session exists or not), remember when you redirect the page send the url of the current page in parameters to your login page so that when the user logs in he can be redirected back to the previous page and click on apply for that particular job.....
This is how the logic works, if you want the php, mysql explanation it would take some time for you to understand as you yourself conceded you are new to php..

Share:
12,985
amol
Author by

amol

Updated on June 04, 2022

Comments

  • amol
    amol almost 2 years

    I am doing a web-application using PHP for job searching.

    I have one query; when user is not logged in and wants to apply for the job given by clicking 'apply' button, he redirects to the login page. If the user is logged in when clicking, he should get directly to the application page. I'm not sure how to implement this.

    I'm confused because I'm new to PHP.