Redirect using a Buffer
Posted: Thu Feb 22, 2007 11:05 am
Hello. I have a login page that when correct information is submitted, redirects to a new page. My problem is the issue that no data can be send before the header() statement. I currently have include()s that are at the begining, which contain my password info for mySQL database, which I connect to in order to run sanatizing scripts, etc.
So, the includes have to remain as far as I can tell. After searching for a while, I came across the php buffer. I 'think' this means I could put the include()s in the buffer, but I can not figure out the order works... in other words...
Is Buffering a good option for this problem? If so, I can not figure out when to call the buffer and buffer flushing commands. The Order of everything must remain I think, since I have to have the password include() in order to be able to access mySQL for sanitizing, then checking if the login data matches the database, THEN submitting the header redirect if login verified.
Any ideas on how to make this work as intended? Or is this not possible with my current setup, and would JavaScript be better then?
Thank you for any and all help.
-Mike-
So, the includes have to remain as far as I can tell. After searching for a while, I came across the php buffer. I 'think' this means I could put the include()s in the buffer, but I can not figure out the order works... in other words...
Code: Select all
ob_start();
include_once('xPath.inc.php');
include_once($pathRoot.'password.inc.php');
include_once($pathClass.'mysqldb.class.php');
// perhaps here would go ob_end_flush() ????
//Open Connection to Database
$db = new MySQLClass();
$db->connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD);
$db->select(MYSQL_DB);
//Sanitize Inputs from SESSION and POST
sanitize_inputs();
// I then use some if else statements to find out if the login information is the same as the database, $dataPresent is defined for the below if statement, and no includes or any information is passed to the browser in all this code.
if ($dataPresent == "yes" ) {
header("location: http://www.domain.com/directory/workshop.php");
exit;
}Any ideas on how to make this work as intended? Or is this not possible with my current setup, and would JavaScript be better then?
Thank you for any and all help.
-Mike-