View Full Version : php redirect after headers

11-10-2007, 12:41 AM
I have a page that I have to check for account type and if its type a I need to redirect but if its type b have it stay. Ideas?

11-10-2007, 12:41 AM
I tryied to use httpresponse::redirect() it told me class not found, also tried http_redirect() nothing.

11-10-2007, 12:44 AM
are you looking for ... ?

header("Location: otherpage.htm");

BTW if headers have already been set... well they should not have been ;) , you can however suppress header errors by starting your page with ob_start();

11-10-2007, 12:56 AM
I told the dev team manager that and he said that is a hack! because I wrote the following

// gets the account id
$acc_id = $session->getAccountId();
$ck_type = "SELECT seller_customers_id FROM can_seller_profile WHERE seller_customers_id ='$acc_id'";
$res_ck = mysql_query($ck_type);
$ck_r = mysql_num_rows($res_ck);
if($ck_r != 0 ){
//Rest of page load

am I wrong in assume this isn't a hack?

11-10-2007, 01:19 AM
No, it's not a hack.

11-10-2007, 04:04 AM
whether its a hack depends on more than the code supplied, if by the time that code is run headers have already been set (or any content has been echoed) then its a hack.

If no output has been sent and therefore no http headers sent then no it is not a hack...
....unless you could have predicted this failure before getting to this page in the first place... which makes it a hack again ;)

as a general rule I think that if you need to use ob_start() just to supress header warnings then its probably a hack, if not then probably not, but thats quite subjective and I don't know your dev team manager :)

11-10-2007, 05:49 PM
if you're working on an MVC-style system, then using header() in the middle of the flow isn't ideal.

Your first page mentioned a 'httpresponse' object. Do you have one, or were you just guessing (based on a language other than PHP perhaps...)? If you do, then it would make sense for the Response class to deal with redirecting.