Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2007, 11:41 PM   PM User | #1
moos3
Regular Coder

 
Join Date: Aug 2007
Location: maine,usa
Posts: 151
Thanks: 2
Thanked 1 Time in 1 Post
moos3 is an unknown quantity at this point
php redirect after headers

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?
__________________
Just a simple Developer and IT student
My Blog
My Portfolio
My Playground of Technology
moos3 is offline   Reply With Quote
Old 11-09-2007, 11:41 PM   PM User | #2
moos3
Regular Coder

 
Join Date: Aug 2007
Location: maine,usa
Posts: 151
Thanks: 2
Thanked 1 Time in 1 Post
moos3 is an unknown quantity at this point
I tryied to use httpresponse::redirect() it told me class not found, also tried http_redirect() nothing.
__________________
Just a simple Developer and IT student
My Blog
My Portfolio
My Playground of Technology
moos3 is offline   Reply With Quote
Old 11-09-2007, 11:44 PM   PM User | #3
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,911
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
are you looking for ... ?

PHP Code:
<?
if(!$some_condition){
    
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();
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

Last edited by firepages; 11-09-2007 at 11:46 PM..
firepages is offline   Reply With Quote
Old 11-09-2007, 11:56 PM   PM User | #4
moos3
Regular Coder

 
Join Date: Aug 2007
Location: maine,usa
Posts: 151
Thanks: 2
Thanked 1 Time in 1 Post
moos3 is an unknown quantity at this point
I told the dev team manager that and he said that is a hack! because I wrote the following
PHP Code:
// 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 != ){
    
header("Location:/settings.php");
}
//Rest of page load 
am I wrong in assume this isn't a hack?
__________________
Just a simple Developer and IT student
My Blog
My Portfolio
My Playground of Technology
moos3 is offline   Reply With Quote
Old 11-10-2007, 12:19 AM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
No, it's not a hack.
Inigoesdr is offline   Reply With Quote
Old 11-10-2007, 03:04 AM   PM User | #6
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,911
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 11-10-2007, 04:49 PM   PM User | #7
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
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.
__________________
My thoughts on some things: http://codemeetsmusic.com
And my scrapbook of cool things: http://gjones.tumblr.com
GJay is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:44 AM.


Advertisement
Log in to turn off these ads.