Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 9 of 9

Thread: Useful Information about Function Header (PHP)

  1. #1

    Useful Information about Function Header (PHP)

    heya!


    For a long time I have many problems with function Header in PHP. This cause an error of outup buffering when we have something like this:
    PHP Code:
    <?php 
    echo "Hi world!";
    header ("location: main.php");
    ?>
    this cause a error that i refer previous. The first solution for this was using javascript like this:

    PHP Code:
    echo "<SCRIPT>window.location=\"main.php\"; </SCRIPT>"
    but this isn't very good because when user click back on browser isn't possible, this function not permit Back.

    Then I have to found another solution , finally
    like this:

    PHP Code:
    <?php 
    ob_start
    ();

      echo 
    "Hi world!";
      
    header ("location: main.php");

    ob_end_flush();
    ?>
    Using this functions (ob_start(); and ob_end_flush(); ), we can have many outputing to buffer without cause error

    You can found more information about this functions in
    www.php.net

    I test this in PHP 4.0.6 and 4.3.1

    I hope this help someone
    xauz!

  2. #2
    well if you are going to do that, then why not just take the output code (echo) out. The ob_start disallows output being displayed... so that entire code could be shortened to

    PHP Code:
    <?
    header
    ("Location: whereever.php");
    ?>

  3. #3
    4,029
    posts
    home cooking is killing the restaurant industry
    There are only 10 kinds of people in this world:
    Those that might know ternary, those that do, and those that don't
    Say NO to DRM.

  4. #4
    Jubba can be but if you need to have something like this

    PHP Code:
    <?php

    if ($status == "loginok") {

     echo 
    "Validation Ok!"

    }else {


    header ("location: main.php");
    }

    ?>
    you can't have only header ("location: main.php");


  5. #5
    look at your code again. That would work without using the ob_start/ob_flush because of the if statement. If its not true then there is no output and the header gets parsed... if the statement is true... the output is run and the header doesn't get parsed...

  6. #6
    No... don't works .... the logical is that work but not ...

    As i was sad, i test in versions 4.0.6 and 4.3.1 ...

  7. #7
    works fine on: 4.3.2

    must be the older versions... but I never had trouble with this before I upgraded my server...

    eh whatever...

  8. #8
    Doesn't PHP have HTTP Headers like ASP?

  9. #9

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012