TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-20-2008, 04:28 PM   #1 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default 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
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 04-20-2008, 06:11 PM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

do this
PHP Code:
<?print_r(headers_sent());?>
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 04-20-2008, 06:19 PM   #3 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

i did it and it give the number 1 !
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 04-20-2008, 06:23 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 04-20-2008, 06:44 PM   #5 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

but the html code MUST be before the php
so i can mix design and php
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 04-20-2008, 06:46 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

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

or you could do $header_%theheadernamehere% = header("fff");
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 04-20-2008, 07:01 PM   #7 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 04-20-2008, 11:14 PM   #8 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

so can u write here a little exemple plz
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 04-21-2008, 02:56 AM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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 View Post
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.
__________________

Village Idiot is offline  
Reply With Quote
Old 04-21-2008, 11:42 AM   #10 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
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
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 04-21-2008, 12:44 PM   #11 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by webtuto View Post
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.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:07 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design