|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to use ob_start();
how to use ob_start? what is its function?
In last few forum, i have post my problem and i get the response tat suggest i can use the ob_start. But i not really understand its meaning n how to use in my coding ?? i add ob_start(); at the top of coding but my problem still can't settle. Warning: Cannot send session cache limiter - headers already sent (output started at c:\web\wai\cart.php:3) in c:\web\db.php on line 43 *php code function GetCartId() { if(isset($_COOKIE["cartId"])) { return $_COOKIE["cartId"]; } else { session_start(); setcookie("cartId", session_id(), time() + ((3600 * 24) * 30)); (line 43) return session_id(); } } can i know what is the problem and how to use ob_start(); which suggest for me in last forum?10q |
|
#2
|
|||
|
|||
|
ob_start(); clears the browser's header.
what i do in my scripts i add ob_start(); at the top of the page & ob_end_flush(); at the bottom.. so: PHP Code:
the cause of your problem may not be because you did not use ob_start(); check to make sure you dont have any whitespace or newlines.
__________________
![]() ![]() "Only Linux users see the end of crashes." - Pl4t0 |
|
#3
|
|||
|
|||
|
Actually, ob_start() tells PHP to start output buffering, meaning that anything you output after ob_start() wont be sent to the browser until the end of the page or ob_end() etc are reached.
So that means that once you use ob_start() and echo something out, you can still set cookies without any errors. For example: <?php ob_start(); echo "this will work"; setcookie("test", true); ob_end_flush(); ?> etc... ![]() |
|
#4
|
|||
|
|||
|
newline&whitespaces
is it whitespace or newlines mean like print,echo???
i should check that in that page? in whole db.php i didn't put any echo on it. tat is whole coding in db.php(same as in tutorial) <? $dbServer = "localhost"; $dbUser = "user"; $dbPass = "password"; $dbName = "db"; function ConnectToDb($server, $user, $pass, $database) { // Connect to the database and return // true/false depending on whether or // not a connection could be made. $s = @mysql_connect($server, $user, $pass); $d = @mysql_select_db($database, $s); if(!$s || !$d) return false; else return true; } function GetCartId() { // This function will generate an encrypted string and // will set it as a cookie using set_cookie. This will // also be used as the cookieId field in the cart table if(isset($_COOKIE["cartId"])) { return $_COOKIE["cartId"]; } else { // There is no cookie set. We will set the cookie // and return the value of the users session ID session_start(); setcookie("cartId", session_id(), time() + ((3600 * 24) * 30)); return session_id(); } } ?> |
|
#5
|
|||
|
|||
|
actually my shopping cart can run and function but just in the top of shopping cart appear the warning like that
Warning: Cannot send session cache limiter - headers already sent (output started at c:\web\wai\cart.php:3) in c:\web\db.php on line 43 how i can make it disappear?? |
|
#6
|
|||
|
|||
|
thanks to mytch for enlightening me
![]() try adding ob_start(); just before you set your cookie and ob_end_flush(); after you set it. |
|
#7
|
|||
|
|||
|
as mytch said ob_start buffers the header, so its not sent out till the end of the page, or you use ob_end, etc
in your case wailin, using $_COOKIES, sets the header. If you do what war-angel said, by placing a ob_start before your cookie call it should stop the header being sent out, which will stop that message from apearing. here are some functions/variables that set the header. $_COOKIE setcookie header if you want to find out at any stage if the headers have already been sent (this is good for debugging) try using this function headers_sent returns true if headers have been sent. |
|
#8
|
|||
|
|||
|
Just to clarify, ob_start() buffers content NOT headers.
Hadley |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > how to use ob_start(); |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|