Everytime I create a website or application in PHP I must use the header() function to redirect people from page to page, but since the typical header is almost always sent before I find myself having to use output buffering functions that slow down the page. It's either that or suppress the "header already sent" errors. I just can't really find any example where an application can be built in PHP without having to violate either the two.
I am trying to know more, about how some redirect to pages without using output buffering.
edit
This is what some people assume is the possible.
<?php
$stack_errors = NULL;
if($_POST && isset($_POST['username']) && isset($_POST['password'])){
$stmt = $pdo->prepare('SELECT * FROM users where username = ? AND password = ?');
$stmt->execute(array($_POST['username'], $_POST['password']);
if($stmt->rowCount() == 0){
$stack_errors = 'error, username or password is incorrect';
}else{
$stack_errors = false;
}
}else{
$stack_errors = 'please enter username and password to log in';
}
if(false === $stack_errors){
header('Location: /success.php');
exit;
}
?>
<html>
<head></head>
<body>
<form>
<input ...>
<input ...>
<?php if($stack_errors){
echo $stack_errors;
}
<form>