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 6817195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:01:10+00:00 2026-05-26T21:01:10+00:00

I have a login screen with username and password credentials that are validated throught

  • 0

I have a login screen with username and password credentials that are validated throught a php script. once a user enters their username and password and hits submit. authenticate.php does an LDAP bind and if the user’s credentials are legit they are redirected to say http://www.siteA.com, if the credentials are false an erorr is given saying “Invalid login, authentication failed. I would like to make this AJAX so when a user hits submit, right on that page it tells the user whether they entered valid or invalid login.

Below is my code:

For login form:

<form action=authenticate.php method=post name=Auth class="appnitro">
    <div class="form_description">
    <h2>Login</h2>
    </div>
<ul>
        <li id="li_1">
    <label class="description" for="element_1">Username </label>
        <div>
        input id="element_1" name="login" class="element text medium" type="text" maxlength="255" value=""/>
        </div>
    </li>
        <li id="li_2" >
        <label class="description" for="element_2">Password </label>
        <div>
        <input id="element_2" name="password" class="element text medium" type="password" maxlength="255" value=""/>
        </div>
    </li>
        <li class="buttons">
            <input id="saveForm" class="button_text" type="submit" name="submit" value="Log In" />
    </li>
    </ul>
</form>

My LDAP Bind, Authenticate.php:

<?php
    session_start();

    if( isset($_POST['login']) && isset($_POST['password']) )
    {
        //LDAP stuff here.
        $username = trim($_POST['login']);
        $password = trim($_POST['password']);

        echo("Authenticating...");
        $ds = ldap_connect('ldap://ldap:port');

        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

        //Can't connect to LDAP.
        if( !ds )
        {
            echo "Error in contacting the LDAP server -- contact ";
            echo "technical services!  (Debug 1)";

            exit;
        }

        //Connection made -- bind anonymously and get dn for username.
        $bind = @ldap_bind($ds);

        //Check to make sure we're bound.
        if( !bind )
        {
            echo "Anonymous bind to LDAP FAILED.  Contact Tech Services! (Debug 2)";

            exit;
        }

        $search = ldap_search($ds, "ou=People,DC=keler,DC=medioa,DC=com", "uid=$username");

        //Make sure only ONE result was returned -- if not, they might've thrown a * into the username.  Bad user!
        if( ldap_count_entries($ds,$search) != 1 )
        {
            echo "Error processing username -- please try to login again. (Debug 3)";
            redirect(_WEBROOT_ . "/try1b.php");

            exit;
        }

        $info = ldap_get_entries($ds, $search);

        //Now, try to rebind with their full dn and password.
        $bind = @ldap_bind($ds, $info[0][dn], $password);
        if( !$bind || !isset($bind))
        {
            echo "Login failed -- please try again. (Debug 4)";
            redirect(_WEBROOT_ . "/try1b.php");

            exit;
        }

        //Now verify the previous search using their credentials.
        $search = ldap_search($ds, "ou=People,DC=keler,DC=medioa,DC=com", "uid=$username");
        //if the user's login is legit then redirect to the siteA    
        $info = ldap_get_entries($ds, $search);
        if( $username == $info[0][uid][0] )
        {
            $_SESSION['username'] = $username;
            $_SESSION['fullname'] = $info[0][cn][0]; 
            header( "Location: www.siteA.com" );

            exit;
        }
        else
        {
            echo "Error. Access Denied";
            redirect(_WEBROOT_ . "/try1b.php");

            exit;
        }
        ldap_close($ds);
        exit;
    }
?>
  • 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-05-26T21:01:11+00:00Added an answer on May 26, 2026 at 9:01 pm

    no need to paste all that.

    submit the form using Ajax, and have the server-side script return a status and error message.

    if the status indicates the login was successful, do the redirect using JavaScript.

    if the status indicates the login failed, alert the error message.

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

Sidebar

Related Questions

OK, I have a login screen that sends username and password to a PHP
I have a login screen with two textfields (username and password). When the user
I'm trying to create a simple username/password login screen. I have the layout done,
I have an application where the login screen moves the username/password fields up by
I have a login screen with a username and password textbox. However, I've come
I have a login-screen in my iOS app. The username and password will be
I have a login screen where the username & password is entered. I click
I have a login screen that I force to be ssl, so like this:
Normally we have login page with username, password filed and signin button. Using the
I have username and password of user stored in my database, like one time

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.