TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   cannot modify header -plz help- (http://www.talkphp.com/absolute-beginners/2664-cannot-modify-header-plz-help.html)

webtuto 04-20-2008 04:28 PM

cannot modify header -plz help-
 
hey i use this code
im gonna post here a part of it
its an HTML code then php then html

PHP Code:

<HERE THERE IS MORE HTML CODES>
<p>&nbsp;</p>
            <p>&nbsp;</p>
            <p></td>
        <td colspan="5" background="images/Studio_musique_23.gif" valign="top">
            &nbsp;
            <div align="center">
<?php
ob_start
();
include(
"config.php");
if(!empty(
$_POST['nick']) and !empty($_POST['pass']) ) {
$md5=@md5($_POST['pass']);
$nick addslashes($_POST['nick']);
$sql "select * from `membre` where nick='$nick' and pass='$md5'";
$res=mysql_query($sql)or die(mysql_error());
$count mysql_num_rows($res);
if(
$count == 1){

//id fetch-------------------------------------
$wor mysql_query("select * from membre where nick='$nick'")or die(mysql_error());
$oop mysql_fetch_array($wor);
//end id fetch --------------------------------
  
$timestamp_expire time() + 365*24*3600;
setcookie('nick'$_POST['nick'], $timestamp_expire); 
setcookie('pass'md5($_POST['pass']), $timestamp_expire);
setcookie('id'$oop['id'], $timestamp_expire);
echo 
"<meta http-equiv='refresh' content='0;url=userpanel.php'>";
 }else{
 echo
"<center><h2>Le pseado ou le mot de passe est incorrect. Veuillez réessayer.<h2>";
 }
}
ob_end_flush();
?>
<form method="post" action="">
<table border=0>
<tr><td>Pseudo :</td><td><input type="text" name="nick"></td></tr>
<tr><td>Mot de passe :</td><td><input type="password" name="pass"></td></tr>
<tr></td><td><td><input type="submit" name="send" value="      log in      "></td></tr>
</table>
</form>
            </div>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
<HERE THERE IS MORE HTML CODES>

but the problem is that it gives this error


Warning: Cannot modify header information - headers already sent by (output started at /home/karimweb/domains/SITE/login.php:4) in /home/karimweb/domains/public_html/SITE/login.php on line 189

Warning: Cannot modify header information - headers already sent by (output started at /home/karimweb/domains/public_html/SITE/login.php:4) in /home/karimweb/domains/public_html/SITE/login.php on line 190

Warning: Cannot modify header information - headers already sent by (output started at /home/karimweb/domains/public_html/SITE/login.php:4) in /home/karimweb/domains/public_html/SITE/login.php on line 191

and the navigator douesnt register the cookies
the lines 189 and 190 and 191 are the lines where i write the code to register cookies on the browser

Orc 04-20-2008 06:11 PM

do this
PHP Code:

<?print_r(headers_sent());?>


webtuto 04-20-2008 06:19 PM

i did it and it give the number 1 !

delayedinsanity 04-20-2008 06:23 PM

You need to have the PHP above the HTML. Send the headers before anything else, even a blank space, gets sent to the browser. Otherwise, as it's telling you, the headers have already been sent and they can't be set or re-sent after that point.

Code:

<?php /* send your headers */ ?>

<html><!-- do your stuff --></html>

<?php /* clean up behind yourself. Remember, if you sprinkle when you tinkle, be a sweety and wipe the seaty. */ ?>

My phones ringing.
-m

webtuto 04-20-2008 06:44 PM

but the html code MUST be before the php
so i can mix design and php

Orc 04-20-2008 06:46 PM

you can use output buffering to prevent this too. try ob_end_clean.

or you could do $header_%theheadernamehere% = header("fff");

delayedinsanity 04-20-2008 07:01 PM

Quote:

but the html code MUST be before the php
so i can mix design and php
No it doesn't, that's the beauty of PHP. You can easily process everything you need to at the top of the page, and then use it later on down the page. PHP variables aren't restricted to the scope of the current opening and closing tag.

Either way, you don't have much of a choice. You cannot send a header after HTML has already been sent, and there is no way around that. Output buffering offers you a kind of alternative, but really there shouldn't be a need for it.
-m

webtuto 04-20-2008 11:14 PM

so can u write here a little exemple plz

Village Idiot 04-21-2008 02:56 AM

Cookies can only be created before the end of the headers. The headers end right before content is outputted or you end the HTML <head> tag.

Quote:

Originally Posted by webtuto (Post 13675)
but the html code MUST be before the php
so i can mix design and php

Wrong. The PHP engine parses both HTML and PHP, you can mix PHP in with your HTML as much as you want.

webtuto 04-21-2008 11:42 AM

Quote:

Originally Posted by Village Idiot (Post 13694)
Cookies can only be created before the end of the headers. The headers end right before content is outputted or you end the HTML <head> tag.



Wrong. The PHP engine parses both HTML and PHP, you can mix PHP in with your HTML as much as you want.

maan udidnt see the error that it gaves me oof

Village Idiot 04-21-2008 12:44 PM

Quote:

Originally Posted by webtuto (Post 13705)
maan udidnt see the error that it gaves me oof

I am looking at it again. As I said before, it is because the headers have already been sent. Set your cookies before any content is written.


All times are GMT. The time now is 03:36 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0