PHP und LDAP Teil 5

Teil 5:
So das wars, damit Ihr aber jetzt nicht ganz durcheinander seid für euch das Ganze Script.

 

<?php

/*
 * @Author Steven Bohm
 * All Rights Reserved
 *
 */

session_start();
include '../classes/dbCon.class.php';
include '../config.inc.php';
$password = $_POST['password'];
$username = $_POST['username'];
if ($username == "" || $password == "") {
    echo 0;
} else {
//Basis Ordnerstruktur !Rückwärts!
$base_dn = 'OU=Users,OU=usergruppe,DC=firmenname,DC=int';
//Wäre die Ordnerstruktur
// /int/firmenname/usergruppe/Users/

//@ für Späteres einloggen
$ldap_usr_dom = "@fakturaweb";
//Das Passwort aus der Formulareingabe
 $passwd = $password;

//Der AD Server IP oder Domain
 $hostname = 'stevedc01.fakturaweb.de';
    if($ds){
	$r = ldap_bind($ds, $username . $ldap_usr_dom, $passwd);
	}
	else{
	$r = 0;
	}
    if ($r) {
        $sr = ldap_search($ds, $base_dn, $filter);

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

        $mydb = new DB_MySQL($host, $dbname, $user, $pw);

        $mydb->query("SELECT * FROM user_system WHERE user_system_username like '$username'");
        if ($mydb->count() query("INSERT INTO user_system (user_system_name, user_system_street,
            user_system_zipcode,user_system_tele,user_system_mail,user_system_username,
            user_system_pw,user_system_rights) VALUES ('" . $info[0]['cn'][0] . "','" . $info[0]['streetaddress'][0] . "','" . $info[0]['postalcode'][0] . "',
                '" . $info[0]['telephonenumber'][0] . "','" . $info[0]['mail'][0] . "','" . $username . "',MD5('" . $passwd . "'),1);");

            $_SESSION["user_id"] = mysql_insert_id();
            $_SESSION["user_username"] = $username;
            $_SESSION["user_name"] = $info[0]['cn'][0];
            $_SESSION["user_rights"] = "1";
            $_SESSION["logged"] = $_POST['logged'];
        } else {
            $data = $mydb->fetchRow();

            $_SESSION["user_id"] = $data["user_system__ID"];
            $_SESSION["user_username"] = $data["user_system_username"];
            $_SESSION["user_name"] = $data["user_system_name"];
            $_SESSION["user_rights"] = $data["user_system_rights"];
            $_SESSION["logged"] = $_POST['logged'];
        }

        echo 1;
        ldap_close($ds);

    } elseif (!$r) {
        $mydb = new DB_MySQL($host, $dbname, $user, $pw);
        $mydb->query("SELECT * FROM user_system WHERE user_system_username like '$username' AND user_system_pw = MD5('$passwd')");

        if ($mydb->count() > 0) {
            // Benutzerdaten in ein Array auslesen.
            $data = $mydb->fetchRow();

            // Sessionvariablen erstellen und registrieren

            echo 1;
            $_SESSION["user_id"] = $data["user_system__ID"];
            $_SESSION["user_username"] = $data["user_system_username"];
            $_SESSION["user_name"] = $data["user_system_name"];
            $_SESSION["user_rights"] = $data["user_system_rights"];
            $_SESSION["logged"] = $_POST['logged'];
        }
    } else {

        echo 0;
    }
}
?>

Schreibe einen Kommentar