Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post

    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

  • #2
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    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

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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();
    Last edited by firepages; 11-09-2007 at 11:46 PM.
    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)

  • #4
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    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

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    No, it's not a hack.

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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)

  • #7
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •