Skip to content
Advertisement

PHP not redirecting on Ubuntu Server

I’ve built a website login form on my local Windows machine that works perfectly but when deployed on an Ubuntu web server, the login for redirects to /login.php#

Below is the code used –

<!DOCTYPE html>
<html>
<head>

</head>

<body>

<?php

session_start();

    if(isset($_POST['username']) && isset($_POST['password']) and $_POST['username'] !="" and $_POST['password'] !="") {

    $adServer = "SECRET";

    $ldap = ldap_connect($adServer);
    $username = $_POST['username'];
    $password = $_POST['password'];

    $ldaprdn = 'SECRET' . "\" . $username;

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

    $bind = @ldap_bind($ldap, $ldaprdn, $password);

       if ($bind) {
            
            $_SESSION['Authenticated'] = true;
            header("Location: /Web/CSI/indexAuthenticated.php"); 

        } else {
            $msg = "Invalid email address / password";
            echo $msg;
            $_SESSION['Authenticated'] = false;

        }
    
        }else{
?>
    <div class="loginbox">
        <form class="loginform" action="" method="POST">
            <img class="loginlogo" src="img/blue.png" />
            <label class="loginlabel" for="username">Username: </label>
      <?php
            echo "<input class='logininput' id='username' type='text' name='username' value=";
      $userid=get_current_user();
      echo $userid=get_current_user();
      echo ">" ;
            ?>
            <label class="loginlabel" for="password">Password: </label>
            <input class="logininput" id="password" type="password" name="password" />        
            <input type="submit" name="submit" value="Submit" />
        </form>
    </div>

<?php
 } 
?> 

</body>
</html>

LDAP has been uncommented from the extensions section in php.ini on the Ubuntu server.

Is there something Linux specific I’m missing here?

Many thanks, Craig

Advertisement

Answer

So after a lot of playing with the code and banging my head, I realised that I hadn’t installed php_ldap on the new Ubuntu server!

Installed that and the old Windows code worked a charm straight away

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement