Solved! Go to Solution.
<?php function login_check() { if (isset($_SESSION['IWP_loggedIn']) && $_SESSION['IWP_loggedIn'] === true && isset($_SESSION["IWPUser"])) { return true; } else { return false; } } function do_login($username, $password, $redirect) { $un = 'DOMAIN\\' . $username; // Needs the domain ie. mydomain\username $pw = $password; if (empty($un)) { header("Location: http://example.com/sandboxPHP/login.php?error=Username cannot be blank"); exit(); } if (empty($pw)) { header("Location: http://example.com/sandboxPHP/login.php?error=Password cannot be blank"); exit(); } $server = "example.com"; //IP or name of server here if (!($ldap = ldap_connect($server))) { header("Location: http://example.com/sandboxPHP/login.php?error=Could Not Connect To Server"); // can change these error messages exit(); } if (!ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3)) { header("Location: http://example.com/sandboxPHP/login.php?error=Protocol Error with LDAP"); exit(); } if (!($res = @ldap_bind($ldap, $un, $pw))) { header("Location: http://example.com/sandboxPHP/login.php?error=Bind Error with LDAP"); exit(); } else { $_SESSION["IWP_loggedIn"] = true; $_SESSION["IWPUser"] = $un; // Make sure to use appended username with Domain echo $_SESSION["IWPUser"]; //header("Location: " . $redirect); } } function do_logout($redirect) { session_destroy(); header("Location: " . $redirect); } ?>
<?php session_start(); echo $_SESSION["IWPUser"]; require('functions.php'); if(login_check() === false) { echo 'issue'; //header("Location: "); exit(); } else { // rest of your page below } ?>