A
A
Afafks1231321321652020-05-05 17:28:10
PHP
Afafks123132132165, 2020-05-05 17:28:10

Why doesn't it redirect to another page?

header("public_html/index.php"); does not throw on another file. The error pops up: Cannot modify header information - headers already sent by
Here is the code:

<!DOCTYPE html>
<html>
<head>
  <title>Letters</title>  
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
if(isset($_POST["login"]) && isset($_POST["pass"])){
$fd = fopen("nick.txt", 'r');
while(!feof($fd))
{
    $str = htmlentities(fgets($fd));
    if($str == $_POST["login"]){
        break;
    }
}
fclose($fd);

$fd = fopen("passwords.txt", 'r');
while(!feof($fd))
{
    $str = htmlentities(fgets($fd));
    if($str == $_POST["pass"]){
        header("public_html/index.php");
    }
}
fclose($fd);

}
?>
  <div id = "background">
  	<div id = "registration">
  		<form method="POST">
  			<p align="center" id = "text1">Login in.</p>
            <p><input id = "input1" name="login" placeholder="Nickname"></p>
            <p><input id = "input2" name="pass" type="password" placeholder="Password"></p>
            <input id = "input3" type="submit" value="Login in." >
  		</form>
  		<p align = "center" id = "text2">No account? <a id = "a1" href="index.php">Register.</a><p>
  	</div>
  </div>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-05-05
@Afafks123132132165

Because the header function must be called before any output to the stream. You first display the <html> block, and then call header.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question