Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Cannot modify header information.
Old 12-07-2005, 04:05 AM Cannot modify header information.
Average Talker

Posts: 28
Location: Australia
Trades: 0
I am getting the error "Cannot modify header information - headers already sent by..." you know the rest. I have searched and found a number of people asking the same question however I do not understand the responses.

1) White space in the code - how do I find the white space to remove it?
2) No HTML output - sorry how do I get round this?

The php file I am running is:

PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Web Template by Glyndwr D. Bartlett</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta content="CD Copyright © 2005 Glyndwr D. Bartlett" name="description">
<meta content="Glyndwr D. Bartlett" name="author"></head>
<?php
//Quote variable to make safe
function quote_smart($value)
{
//Strip slashes
if (get_magic_quotes_gpc()) {
$value stripslashes($value);
}
//Quote if not integer
if (!is_numeric($value)) {
$value "'" mysql_real_escape_string($value) . "'";
}
return 
$value;
}
//Connect
$link=mysql_connect("127.0.0.1","root")
OR die(
mysql_error());
$db=mysql_select_db("db1",$link);
//Check validity of UserName and Password
if(isset($_POST['LogIn_x'])) {
$query sprintf("SELECT * FROM tbl_user WHERE User_Name=%s AND Password=md5(%s)",
quote_smart($_post['UserName']), quote_smart($_post['PassWord']));
$result mysql_query($query);
$affected mysql_num_rows($result);
if (
$affected != 1) {
session_unset();
echo 
"<font face='Verdana' size='2' color=red>Wrong Login. Use your correct UserID and Password and try again. <br>";
echo 
"<center> <input type='button' value='Retry' onClick='history.go(-1)'></center>";
exit();
}
}
//If Reset was selected we redirect to the homepage.
?>
<?php
if(isset($_POST['Reset_x']))
{
header ("Location: index.php");
exit();
}
?>
</html>
The error comes from the fifth last line header "("Location: index.php");".
The page I am going to is:
PHP Code:
<?
if(file_get_contents("lang.tmp")=="")
{
header("Location: splash.php"); 
exit();
}
?>
<html>
<head>
<meta name="author" content="Glyndwr D. Bartlett">
<title>Kortge Cutlers</title>
<frameset rows="140,*" marginwidth="0" marginheight="0" frameborder="0" border="0" borderwidth="0">
<frame name="head" src="head.php" scrolling=no>
<frameset cols="225,*,225" marginwidth="0" marginheight="0" frameborder="0" border="0" borderwidth="0">
<frame name="navi" src="navi.php" scrolling=auto>
<frame name="content" src="start.php" marginwidth=20>
<frame name="login" src="login.php" marginwidth=20 scrolling=no>
</frameset>
</frameset>
</head>
<body bgcolor=#ffffff>
</body>
</html>
Your help is greatly appreciated.

Regards,

Glyn
GlyndwrBartlett is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-07-2005, 04:39 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
you can't send out redirect headers once output has been sent
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-08-2005, 08:52 AM
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
Code:
<?php
if(isset($_POST['Reset_x']))
{
header ("Location: index.php");
exit();
}
?>
make sure that this the first thing on the page with not so much as a white space before the opening php tag.

The <!doctype html... is unneccessary if the visitor is getting redirected anyway.

the other option it to buffer the output so nothing will be sent til the header situation is resolved using ob_start() but I strongly recommend the first as the most practical and efficient.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 12-08-2005, 11:51 PM
Average Talker

Posts: 28
Location: Australia
Trades: 0
I was able to resolve this problem, with further investigation, by creating a ".htaccess" file and putting the following line in it " PHP_FLAG output_buffering on".

chrishirst: I do not know what you mean.

reli4nt: I will also try your suggestions and let you know if it works.

Regards,

Glyn
GlyndwrBartlett is offline
Reply With Quote
View Public Profile
 
Old 12-09-2005, 03:16 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
As in reli4nt's answer

You are sending the header after the page output has started (The doctype etc). Even sending a single space to the user agent is output and will cause the message to be shown.

Any code using header() must be executed first.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-09-2005, 03:22 AM
Average Talker

Posts: 28
Location: Australia
Trades: 0
Hi reli4nt,

As promised I have tested your solution to the problem. First I removed the file I created and ensured that I had the original problem. I then put your code in. I still had the original problem. I then replaced the file and it worked. So your code is not the resolution. The resolution is the ".htaccess" file containing the line " PHP_FLAG output_buffering on".

I hope this of help to others.

I now have another problem which I will make the subject of another Post.

Regards,

Glyn
GlyndwrBartlett is offline
Reply With Quote
View Public Profile
 
Old 12-09-2005, 06:45 AM
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
Not every one has access to .htaccess.

Would you mind showing me what you code looked like after you tried my fix?
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 12-10-2005, 08:02 AM
Average Talker

Posts: 28
Location: Australia
Trades: 0
Hi Reli4nt,

All too happy to help. I just added the lines you recomended and removed the equivalent lines.

Why is it that not every one has access to ".htaccess"? This may be important for me in the future if I move off my tablet PC.

PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Web Template by Glyndwr D. Bartlett</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta content="CD Copyright © 2005 Glyndwr D. Bartlett" name="description">
<meta content="Glyndwr D. Bartlett" name="author"></head>
<?php
if(isset($_POST['Reset_x']))
{
header ("Location: index.php");
exit();
}
//Quote variable to make safe
function quote_smart($value)
{
//Strip slashes
if (get_magic_quotes_gpc()) {
$value stripslashes($value);
}
//Quote if not integer
if (!is_numeric($value)) {
$value "'" mysql_real_escape_string($value) . "'";
}
return 
$value;
}
//Connect
$link=mysql_connect("127.0.0.1","root")
OR die(
mysql_error());
$db=mysql_select_db("db1",$link);
//Check validity of UserName and Password
if(isset($_POST['LogIn_x'])) {
$query sprintf("SELECT * FROM tbl_user WHERE User_Name=%s AND Password=md5(%s)",
quote_smart($_post['UserName']), quote_smart($_post['PassWord']));
$result mysql_query($query);
$affected mysql_num_rows($result);
if (
$affected != 1) {
session_unset();
echo 
"<font face='Verdana' size='2' color=red>Wrong Login. Use your correct UserID and Password and try again. <br>";
echo 
"<center> <input type='button' value='Retry' onClick='history.go(-1)'></center>";
exit();
}
}
</
html>
Regards,

Glyn
GlyndwrBartlett is offline
Reply With Quote
View Public Profile
 
Old 12-10-2005, 02:07 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Actually the resolution would be to put the redirect part of the code before the doctype rather than change the buffering which could cause other problems.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-12-2005, 03:23 AM
Average Talker

Posts: 28
Location: Australia
Trades: 0
I will try that chrishirst and let you know the result.

Thanks,

Glyn
GlyndwrBartlett is offline
Reply With Quote
View Public Profile
 
Old 12-13-2005, 02:13 AM
Average Talker

Posts: 28
Location: Australia
Trades: 0
Hi chrishirst,

That worked as well. Thanks mate.

Regards,

Glyn

P.s. I don't suppose any one knows how to get the page to load on it's own instead of in the frame it came from, as per my other post?
GlyndwrBartlett is offline
Reply With Quote
View Public Profile
 
Old 12-13-2005, 04:39 PM
Super Talker

Posts: 117
Trades: 0
You can also use your php code this way:

<?php
ob_start();
//your whole script
ob_end_flush();
?>
That will fix all header problems.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
execute is offline
Reply With Quote
View Public Profile Visit execute's homepage!
 
Old 12-13-2005, 11:03 PM
Super Talker

Posts: 117
Trades: 0
BTW your .htaccess thing about PHP_FLAG output_buffering on

Doesn't seem to work well. I get blank pages, but when i use ob_start it works. I have never heard of PHP_FLAG output_buffering on but it sounds cool, but i wasnt able to get it to work.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
execute is offline
Reply With Quote
View Public Profile Visit execute's homepage!
 
Old 12-17-2005, 02:07 PM
Super Talker

Posts: 117
Trades: 0
I dont get blank page i'm sorry i still get "cannot modify cookies" and errors like that, when i use PHP_FLAG output_buffering on
in my Htaccess
however if i type ob_start(); and ob_end_flush(); it works.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
execute is offline
Reply With Quote
View Public Profile Visit execute's homepage!
 
Old 12-17-2005, 03:29 PM
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
Just remember that header() session_start() etc. need to be used before any html is sent to the browser.

When i said to make sure it was the first thing on the page I meant the FIRST thing. This isnt html so you can run a dozen scripts before even the doctype is sent to the browser but once the doctype info or so much as a space occurs outside of the php tags or an echo occurs within then no header info can be sent.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Reply     « Reply to Cannot modify header information.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60095 seconds with 12 queries