You are here: Articles > Computers & Technology > php

 See more articles about "php "

PHP Tutorials - Tutorial Addendum - Using Accolade



 05 December 00:00   

    



    



    

(Continued from antecedent part...)

    



    

I clicked the brace button on the IE window, I got:

    

 

    

Cookies added by the server:

    

Cookie_2: My cookie value

    

Cookies accustomed by the server:

    

Cookie_1 = My cookie value

    



    



    

What happened actuality was that if I opened the page the first time, the server

    

received no cookie from the browser s request. But my page added one cookie

    

named as "Cookie_1" to the response.

    



    

When I clicked the brace button, the browser beatific my cookie aback to

    

the server in the request. Then my page added addition cookie called as

    

"Cookie_2" in the response.

    



    

If I accumulate beat the brace button, added and added accolade would be added

    

to the appeal and response.

    

But there is a limit. The browser will alone yield up to 20 accolade from one Web server.

    



    

Output Ascendancy Functions

    



    

As you can see from setcookie() definition, the PHP engine provides no absorber for the HTTP acknowledgment body.

    

That agency as anon the PHP Software starts to forward achievement to the HTTP acknowledgment body, the HTTP attack block

    

will be finalized, and no accustomed to change.

    



    

But this absence behavior can be adapted by calling achievement ascendancy functions:

    



        

  • setcookie() haveto be alleged afore any achievement to the HTTP response. The capital cause is that

        

    PHP is not buffering the HTTP response. But you can adapt this behavior by using ob_*() functions.

        



  •     

  • ob_start() - A congenital action that turns on achievement buffering.

        



  •     

  • flush() - A congenital action that flushes out the capacity of the achievement absorber to the HTTP acknowledgment body.

        



  •     



    



    

Of course, absence behavior can aswell be adapted by the agreement file, php.ini. Accessible php.ini and set the afterward

    

line:

    

 

    

output_buffering = 4096

    



    



    

The aloft agreement band tells the PHP engine to about-face on achievement buffering, and set the absorber admeasurement to 4096 bytes.

    

Once "output_buffering" is angry on, you don t accept to alarm ob_start() in your scripts.

    



    

To analysis the PHP engine absence behavior, I adapted CookieTest.php into CookieOutputBuffer.php:

    

 

    

<?php #CookieOutputBuffer.php

    

# Absorb (c) 2005 by Dr. Yang, http://www.yang.com/

    

#

    

print("<pre>
");

    

print("Adding accolade by the server:
");

    

$numCookies = count( array_keys($_COOKIE) );

    

$numCookies++;

    

$cookieName = "Cookie_$numCookies";

    

$cookieValue = "My cookie value";

    

print(" $cookieName: $cookieValue
");

    

setcookie($cookieName, $cookieValue);

    

print("
Cookies accustomed by the server:
");

    

foreach ($_COOKIE as $k => $v) {

    

book " $k = $v
";

    

}

    



    

book "</pre>
";

    

?>

    



    



    

I then opened php.ini and set the afterward line:

    

 

    

output_buffering = 0

    



    



    

Running IE on CookieOutputBuffer.php gave me this:

    

 

    

Adding accolade by the server:

    

Cookie_2: My cookie value

    

Cookies accustomed by the server:

    

User = Yang

    

PHP Warning: Cannot adapt attack advice - headers already

    

sent by (output started at ...CookieOutputBuffer.php:4) ...

    



    



    

Now I absolutely beblieve that PHP engine s absence behavior is no achievement buffering. Create abiding to change

    

"output_buffering" aback to 4096 afore continuing to the next test.

    

(Continued on next part...)

    



    



    



 

TAG: output, buffering, server, response, cookies, behavior, engine, default, cookieoutputbuffer, cookiename, numcookies, setcookie, refresh, added, received, browser, button, request,
  output buffering, http response, default behavior, php engine, cookieoutputbuffer php, php ini, response body, server cookie, refresh button, http response body, following line output, line output buffering, cookie valuecookies received, notes using cookies, tutorials tutorial notes, tutorial notes using, php tutorials tutorial,

Share PHP Tutorials - Tutorial Addendum - Using Accolade:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

PHP Tutorials - Tutorial Addendum - Using Accolade
i(Continued from antecedent part...)/iPersistent CookiesThere are two kinds of cookies: assiduous accolade and acting cookies.A assiduous cooki

PHP Tutorials - Tutorial Addendum - Using Accolade
i(Continued from antecedent part...)/iThe setcookie() action offers two added ambit to acquiesce you to set "domain" and "path" backdrop on a cookieas in the afterward syntax:bool setcoo

PHP Tutorials - Tutorial Addendum - Directories, Files and Images
This affiliate describes:Directory functions.File arrangement functions.Image functions.ShowPhoto.php a sample program./

PHP Tutorials - Tutorial Addendum - Directories, Files and Images
i(Continued from antecedent part...)/ifopen Opens book or URLfpassthru Achievement all actual data on a book pointerfputcsv Architecture

PHP Tutorials - Tutorial Addendum - Directories, Files and Images
i(Continued from antecedent part...)/iimagecolorallocate Admeasure a blush for an imageimagecolorat Get the basis of the blush of a pixelimag

PHP Tutorials - Tutorial Addendum - Accepting Non ASCII Characters from Ascribe Forms
This affiliate explains:Basic RulesReceiving Non ASCII Characters with GET MethodReceiving Non ASCII Characters with Column MethodReceiving Non ASCII

PHP Tutorials - Tutorial Addendum - Accepting Non ASCII Characters from Ascribe Forms
i(Continued from antecedent part...)/i3. From move "C3" to "C4", Internet will advance the URL encoded ascribe strings as is. 4. From move "C4" to "C5", Web server will advance the URL encoded ascribe s

PHP Tutorials - Tutorial Addendum - Accepting Non ASCII Characters from Ascribe Forms
i(Continued from antecedent part...)/iCouple of addendum for this script: The "global" account declares all variables in the all around scope. I don t absolutely charge them to bein the all

PHP Tutorials - Tutorial Addendum - Accepting Non ASCII Characters from Ascribe Forms
i(Continued from antecedent part...)/iIf you accessible the dump file, empInputIsoGet.txt, you will see how ascribe strings are URL encoded in query string, and decoded in $_REQUEST.

PHP Tutorials - Tutorial Addendum - Accepting Non ASCII Characters from Ascribe Forms
i(Continued from antecedent part...)/iReceiving Non ASCII Characters in UTF 8In the antecedent scripts, "charset=iso 8859 1" is acclimated for the ascribe page. Now let s play with