0

As the title says, I have a login script. It works on localhost, but it doesn't when I've uploaded it to the webserver. I've tried things like ob_start(), but it still doesn't seem to work.

I've removed the class for the sake of ease, so I'm now using the header() function.

<html>
<header>
    <title>Profiel</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
</header>
<body>

<?php
require_once 'core/init.php';

echo "<div id='main-block' class='main-block'>";

if(Input::exists()) {
        $validate = new Validate();
        $validation = $validate->check($_POST, array(
            'username' => array('required' => true),
            'password' => array('required' => true)
        ));

        if($validate->passed()) {
            $user = new User();

            $remember = (Input::get('remember') === 'on') ? true : false;
            $login = $user->login(Input::get('username'), Input::get('password'), $remember);

            if($login) {
                echo '<br>RD<br>';
                header('Location: index.php', true);
            } else {
                echo '<p>Incorrect username or password</p>';
            }
        } else {
            foreach($validate->errors() as $error) {
                echo $error, '<br>';
            }
        }
}
?>

<table>
<form method="post">
    <tr>
        <div class="field">
            <td><label for='username'>Username</label></td>
            <td><input type="text" name="username" id="username" autocomplete="off"></td>
        </div>
    </tr>
    <tr>
    <div class="field">
        <td><label for='password'>Password</label></td>
        <td><input type="password" name="password" id="password"></td>
    </div>
    </tr>
    <tr>
    <div class="field">
        <td><label for="remember">
            <input type="checkbox" name="remember" id="remember">Remember me
        </label></td>
    </div>
    </tr>

    <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
    <tr><td><input type="submit" name='submit' value="Login"></td></tr>
</form>
</table>

</div>
</body>
</html>

I hope someone has got the solution for me!

  • 1
    Look in your error log for `headers already sent` – RiggsFolly Feb 09 '17 at 21:49
  • That code should never work anywhere – RiggsFolly Feb 09 '17 at 21:49
  • @RiggsFolly can you explain why? –  Feb 09 '17 at 21:51
  • @LexdeWilligen you are not allowed to send headers after you've written anything that belongs to the page. – apokryfos Feb 09 '17 at 21:52
  • And can you remove the duplicate, my question obviously needs a different answer since all of the solutions don't seem to work! –  Feb 09 '17 at 21:52
  • No its an obvious Duplicate. As soon as you send `` to the browser, you can no longer send a `header()` as all headers have already been sent as soon as you code `` – RiggsFolly Feb 09 '17 at 21:54
  • Well then, but why does it work on my USBwebserver?? –  Feb 09 '17 at 21:56
  • I dont know USBWebserver but if it works on that then you need to use a better development server that is more compliant with your intended LIVE server – RiggsFolly Feb 09 '17 at 22:00
  • But personally I would check the error logs on your USBWebServer – RiggsFolly Feb 09 '17 at 22:01
  • I don't get an error... –  Feb 09 '17 at 22:15
  • Well you should get an error. As you see on a serious serer you do get an error – RiggsFolly Feb 09 '17 at 22:22
  • I just checked out USBWebServer. Wow PHP5.3[not supported since Aug 2014] (current is PHP7.1) Apache 2.2.21 (Current is 2.4.25) MYSQL 5.5 (Current is 5.7) – RiggsFolly Feb 09 '17 at 22:27
  • That must be the reason then! I've fixed my own problem. I've used some javascript to redirect, and it works now. Thanks for at least taking a look at my problem! –  Feb 09 '17 at 22:30

0 Answers0