<span id="0rqm0"></span>

    ...<\/form><\/body><\/html><\/pre>

    Code like that is common. Using variables to show status messages has limitations. They cannot be send via redirects (unless you propagate them as GET variables to the next script , which is very silly). In large scripts there might be multiple messages etc.<\/p>

    Best way is to use session to propagate them (even if on same page). For this there has to be a session_start on every page.<\/p>

    function set_flash($msg){    $_SESSION['message'] = $msg;}function get_flash(){    $msg = $_SESSION['message'];    unset($_SESSION['message']);    return $msg;}<\/pre>   

    and in your script :<\/p>

    
    

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Status is : ...<\/form><\/body><\/html><\/pre> 5. Make your functions flexible
    function add_to_cart($item_id , $qty){    $_SESSION['cart'][$item_id] = $qty;}add_to_cart( 'IPHONE3' , 2 );<\/pre>   

    When adding a single item you use the above function. When adding multiple items , will you create another function ? NO. Just make the function flexible enough to take different kinds of parameters. Have a closer look :<\/p>

    function add_to_cart($item_id , $qty){    if(!is_array($item_id))    {        $_SESSION['cart'][$item_id] = $qty;    }    else    {        foreach($item_id as $i_id => $qty)        {            $_SESSION['cart'][$i_id] = $qty;        }    }}add_to_cart( 'IPHONE3' , 2 );add_to_cart( array('IPHONE3' => 2 , 'IPAD' => 5) );<\/pre>   

    So now the same function can accept different kinds of output. The above can be applied in lots of places to make your code more agile.<\/p> 6. Omit the closing php tag if it is the last thing in a script

    I wonder why this tip is omitted from so many blog posts on php tips.<\/p>

       

    This will save you lots of problem. Lets take an example :<\/p>

    A class file super_class.php<\/p>

    \/\/super extra character after the closing tag<\/pre>   

    Now index.php<\/p>

    require_once('super_class.php');\/\/echo an image or pdf , or set the cookies or session data<\/pre>   

    And you will get Headers already send error. Why ? because the \"super extra character\" has been echoed , and all headers went along with that. Now you start debugging. You may have to waste many hours to find the super extra space.<\/p>

    Hence make it a habit to omit the closing tag :<\/p>

       

    Thats better.<\/p> 7. Collect all output at one place , and output at one shot to the browser

    This is called output buffering. Lets say you have been echoing content from different functions like this :<\/p>

    function print_header(){    echo \"