General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 2nd, 2003, 12:40 AM
wailin wailin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 wailin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old January 2nd, 2003, 03:35 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 13
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
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:
<?php
ob_start
();

// code 

ob_end_flush();
?>


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

Reply With Quote
  #3  
Old January 2nd, 2003, 03:38 AM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
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...


Reply With Quote
  #4  
Old January 2nd, 2003, 03:44 AM
wailin wailin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 wailin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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();
}
}


?>

Reply With Quote
  #5  
Old January 2nd, 2003, 04:09 AM
wailin wailin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 wailin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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??

Reply With Quote
  #6  
Old January 2nd, 2003, 04:40 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 13
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
thanks to mytch for enlightening me

try adding ob_start(); just before you set your cookie and ob_end_flush(); after you set it.

Reply With Quote
  #7  
Old January 2nd, 2003, 04:54 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.

Reply With Quote
  #8  
Old January 2nd, 2003, 05:47 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Just to clarify, ob_start() buffers content NOT headers.

Hadley

Reply With Quote
  #9  
Old January 20th, 2010, 11:45 PM
DhavalShingala DhavalShingala is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 2 DhavalShingala User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 53 sec
Reputation Power: 0
Hi Wilin

just write <?php error_reporting(E_PARSE); ?> on the top of ur php file so the warning disable..

Reply With Quote
  #10  
Old January 20th, 2010, 11:48 PM
DhavalShingala DhavalShingala is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 2 DhavalShingala User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 53 sec
Reputation Power: 0
hi wailin
just write <?php error_reporting(E_PARSE); ?> on top of the php file so warning disable...

Reply With Quote
  #11  
Old May 14th, 2010, 09:51 AM
Loop1 Loop1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2010
Posts: 2 Loop1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 2 sec
Reputation Power: 0
ooh,so interesting info)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > how to use ob_start();


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap