Reply to Re: sending multiple headers (session_start() and setcookie() )

Your name:

Reply:


Posted by Chris Hope on 01/07/05 07:46

Ben wrote:

> In my .php file, I'm using both session_start() and setcookie() before
> <html> tag. It gives me following warning message:
>
> Warning: Cannot modify header information - headers already sent by
> (output started at D:\Apache Group\Apache2\htdocs\YC\songs.php:4) in
> D:\Apache Group\Apache2\htdocs\YC\ycphpfunc.php on line 148
>
> My .php file looks like this:
>
> <?php session_start(); ?>
>

It looks to me like there's white space (a line break) right here
inbetween the closing ?> and opening <?php I'm not sure why you've
coded it like this though. Why not just have one code block? See my
example below.

> <?php
> ob_start();
> include 'ycphpfunc.php';
> $login = new login_class;
> if ($_POST[logusername] == "" || $_POST[logpassword] == "") {}
> else {
> $login->check_login($_POST['logusername'], $_POST['logpassword'],
> $_POST['remember']);
> }
> ob_end_flush();
> ?>
> <html>
> .......
> .......
> </html>
>
> The call to check_login()calls setcookie() function through another
> function inside my "ycphpfunc.php" file.
>
> Can someone show me a way to include both session_start() and
> setcookie() before <html>?

Change it to be like this:

<?php
session_start();
        ob_start();
...


or like this:

<?php
        ob_start();
session_start();
...

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация