When submitting a form, I am receiving this warning:
Warning: Cannot modify header information - headers already sent by (output started at /home/domainname/public_html/test.php:4) in /home/basewars/domainname/test.php on line 19
I've had a look at How to fix "Headers already sent" error in PHP and I believe it is because I am echoing the <title>
, however I cannot think of a way around this.
<!DOCTYPE html>
<html lang="en">
<head>
<?php
if(strpos($_SERVER["SCRIPT_NAME"], 'user') == true) {
echo '<title>'.$username.' - Hello</title>';
}else{
echo '<title>Hello</title>';
}
?>
</head>
<body>
<form method="post">
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])) {
header('Location: login.php');
exit();
}
?>
</body>
</html>