Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:00:24+00:00 2026-06-03T22:00:24+00:00

I have a webpage. The authentication to the webpage is handled by a ldap

  • 0

I have a webpage. The authentication to the webpage is handled by a ldap server I have set up. Now I wan`t to implement sessions, so that when a user is inactive for a period of time (in the case below, 10 seconds), the session will end and the user will unbind from the ldap server. I found this excerpt of code:

<?php
    session_cache_expire(20);

    session_start(); 
    $inactive = 10;
    if(isset($_SESSION['start'])) {
        $session_life = time() - $_SESSION['start'];
        if($session_life > $inactive){
            header("Location: endSession.php"); 

        }
    }
    $_SESSION['start'] = time();
?>

It is not working. If I refresh the page it redirects me to my ‘endSession.php’ page, even if I`m active.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:00:26+00:00Added an answer on June 3, 2026 at 10:00 pm
    function check_auth_ldap () {
    
      $sessionTimeoutSecs = 10;
      $ldapServer = '11.22.33.44';
      $ldapPort = 389;
    
      if (!isset($_SESSION)) session_start();
    
      if (!empty($_SESSION['lastactivity']) && $_SESSION['lastactivity'] > time() - $sessionTimeoutSecs && !isset($_GET['logout'])) {
    
        // Session is already authenticated
        $ds = ldap_connect($ldapServer, $ldapPort);
        if (ldap_bind($ds, $_SESSION['username'], $_SESSION['password'])) {
          $_SESSION['lastactivity'] = time();
          return $ds;
        } else {
          unset($_SESSION['lastactivity'], $_SESSION['username'], $_SESSION['password']);
          header("Location: endSession.php");
          exit;
        }
    
      } else if (isset($_POST['username'], $_POST['password'])) {
    
        // Handle login requests
        $ds = ldap_connect($ldapServer, $ldapPort);
        if (ldap_bind($ds, $_POST['username'], $_POST['password'])) {
          // Successful auth
          $_SESSION['lastactivity'] = time();
          $_SESSION['username'] = $_POST['username'];
          $_SESSION['password'] = $_POST['password'];
          return $ds;
        } else {
          // Auth failed
          header("Location: endSession.php");
          exit;
        }
    
      } else {
    
        // Session has expired or a logout was requested
        unset($_SESSION['lastactivity'], $_SESSION['username'], $_SESSION['password']);
        header("Location: endSession.php");
        exit;
    
      }
    
    }
    

    Just call the above function at the top of every protected page. This will handle all the authentication processes. It will return the LDAP connection resource if the user is authenticated, and redirect them to endSession.php if they are not.

    Just place this line at the top of each page:

    $ds = check_auth_ldap();
    

    …and the function will do all the legwork for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage that redirects to another webpage like this: http://www.myOtherServer.com/Sponsor.php?RedirectPage=http://mylink.com/whereIwasgoingtogo.html Then the
I have a webpage that displays a very large list of data. Since this
I have a webpage that I don't have the ability to change the underlying
I have a webpage that activates a print job on a printer. This works
I have a webpage that displays a calendar, and I want to change the
I have an ASP.NET website set up using Windows authentication. Each time I open
I have a webpage that I only want a specific group to log into.
I have a webpage that does a lot of processing in JavaScript and creates
I have a webpage that uses some hidden textarea fields - for storing some
I have a webpage with a form element and a popup window (opened by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.