473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Please help. That darn header command

I'm hoping someone can help me with this. I've seen and tried various
solutions I've seen on the net, but nothing works.

Of course it works perfectly on localhost, but when I upload it to the
server (1and1.com) it gives errors. The user enters a code, the code is
verified, a new one is created and it's supposed to send them to the next
page.
if (CodeExist($cCode) > 0){
$cNewCode = MakeCode();
$ok = InsertRec($cNewCode);

ob_start(); // doesn't matter if I leave this in or take it out.
session_cache_limiter('public'); // suggestion from the internet. No
effect :(
session_start();
$_SESSION['newcode'] = $cNewCode;

print "session is set to:".$_SESSION['newcode'];
header("Location: info.php");
exit;

And here's the output. Notice that the session was set even through the
error messages:

Warning: Cannot send session cookie - headers already sent by (output
started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20

Warning: Cannot send session cache limiter - headers already sent (output
started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20
session is set to:JSG598
Warning: Cannot add header information - headers already sent by (output
started at /devel/joinnow.php:4) in /devel/joinnow.php on line 25

Any help would be extremely helpful!
Thanks!!
Jul 17 '05 #1
6 3376
Update! I created two php test pages. Page 1 redirected to page 2. It
worked on my localhost AND on the internet server. So I'm scratching my
head thinking "What the hell?". THEN I tried it using my Dreamweaver
template. Holy crap, the simple one line redirection worked on my
localhost, but not on the internet server.

The Dreamweaver template is causing the mess!! Has any one else experienced
this and figured out how to fix it?

"Lochness" <so*****@somewhere.com> wrote in message
news:mOIcc.37239$Pk3.11329@pd7tw1no...
I'm hoping someone can help me with this. I've seen and tried various
solutions I've seen on the net, but nothing works.

Of course it works perfectly on localhost, but when I upload it to the
server (1and1.com) it gives errors. The user enters a code, the code is
verified, a new one is created and it's supposed to send them to the next
page.
if (CodeExist($cCode) > 0){
$cNewCode = MakeCode();
$ok = InsertRec($cNewCode);

ob_start(); // doesn't matter if I leave this in or take it out.
session_cache_limiter('public'); // suggestion from the internet. No
effect :(
session_start();
$_SESSION['newcode'] = $cNewCode;

print "session is set to:".$_SESSION['newcode'];
header("Location: info.php");
exit;

And here's the output. Notice that the session was set even through the
error messages:

Warning: Cannot send session cookie - headers already sent by (output
started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20

Warning: Cannot send session cache limiter - headers already sent (output
started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20
session is set to:JSG598
Warning: Cannot add header information - headers already sent by (output
started at /devel/joinnow.php:4) in /devel/joinnow.php on line 25

Any help would be extremely helpful!
Thanks!!

Jul 17 '05 #2
In article <xvLcc.40778$Ig.8376@pd7tw2no>,
"Lochness" <so*****@somewhere.com> wrote:
The Dreamweaver template is causing the mess!! Has any one else experienced
this and figured out how to fix it?


Probably empty lines or spaces somewhere. If you do a header("Location:
"), there is no output of any sort allowed before that. And that
includes white space before the <?php declaration.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #3
Rob

"Jan Pieter Kunst" <de*****@cauce.org> schreef in bericht
news:de***************************@news1.news.xs4a ll.nl...
In article <xvLcc.40778$Ig.8376@pd7tw2no>,
"Lochness" <so*****@somewhere.com> wrote:
The Dreamweaver template is causing the mess!! Has any one else experienced this and figured out how to fix it?


Probably empty lines or spaces somewhere. If you do a header("Location:
"), there is no output of any sort allowed before that. And that
includes white space before the <?php declaration.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.


<snip> from previous post

if (CodeExist($cCode) > 0){
$cNewCode = MakeCode();
$ok = InsertRec($cNewCode);

ob_start(); // doesn't matter if I leave this in or take it out.
session_cache_limiter('public'); // suggestion from the internet. No
effect :(
session_start();
$_SESSION['newcode'] = $cNewCode;

print "session is set to:".$_SESSION['newcode'];
header("Location: info.php");
exit;

</snip>

It is not probably it is definitely. Look at the print statement.
If you want to change the header information then this is the first thing
send back to the client. When sending white spaces, using echo's or print
statements the header information is automatically send. The message:
"Warning: Cannot send session cache limiter - headers already sent" is
telling you did send something before using the header function. it is even
telling you where you did this (hence the line "/devel/joinnow.php on line
20").

I don't know where you got your suggestions or other information from the
internet but www.php.net is a good place to start. Look at
http://www.php.net/manual/nl/function.header.php first ;-)
HTH rob
Jul 17 '05 #4
Lochness wrote:
Update! I created two php test pages. Page 1 redirected to page 2. It
worked on my localhost AND on the internet server. So I'm scratching my
head thinking "What the hell?". THEN I tried it using my Dreamweaver
template. Holy crap, the simple one line redirection worked on my
localhost, but not on the internet server.

The Dreamweaver template is causing the mess!! Has any one else
experienced this and figured out how to fix it?


Don't use Dreamweaver? Seriously the only stuff I'd trust to use
'auto-code' for is flat, boring, static HTML. I've seen all sorts of
weirdness and client incompatibility from code generated in various IDE's
(Like Dreamweaver). Unless you are stuck with it, maybe try hand-cranking
your code 'ye olde fashioned' way.

Not much help, I know, but thought I'd throw my $0.02 in.

Good luck,

James
--
Fortune cookie says:
Do unto others before they undo you.

Jul 17 '05 #5
Thank you so much guys!!
After reading your replies I created a little test. With my template I
created a one statement page and at the top added:
--------------------
<?php error_reporting(E_ALL);?>

<?php
header("Location: test2.htm");
?>
--------------------
Notice the white space between the two php statements. I sent it up
to my server and it crashed. So I took out the whitespace, sent it up
to my server and it worked!! Then on my big program, I took out all
the blank lines and commented out the print statement. Tada! It
worked!! So thanks to you guys and grrrr to php and it's tightass
attitude towards whitespace.

It worked on my localhost which is version 4.3.4 and the server is
4.2.3. Maybe the newer version isn't as anal about whitespace.

Anyways. Thanks again!!

"Rob" <reply_@news_group.please> wrote in message news:<ef********************@amsnews03.chello.com> ...
"Jan Pieter Kunst" <de*****@cauce.org> schreef in bericht
news:de***************************@news1.news.xs4a ll.nl...
In article <xvLcc.40778$Ig.8376@pd7tw2no>,
"Lochness" <so*****@somewhere.com> wrote:
The Dreamweaver template is causing the mess!! Has any one else experienced this and figured out how to fix it?


Probably empty lines or spaces somewhere. If you do a header("Location:
"), there is no output of any sort allowed before that. And that
includes white space before the <?php declaration.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.


<snip> from previous post

if (CodeExist($cCode) > 0){
$cNewCode = MakeCode();
$ok = InsertRec($cNewCode);

ob_start(); // doesn't matter if I leave this in or take it out.
session_cache_limiter('public'); // suggestion from the internet. No
effect :(
session_start();
$_SESSION['newcode'] = $cNewCode;

print "session is set to:".$_SESSION['newcode'];
header("Location: info.php");
exit;

</snip>

It is not probably it is definitely. Look at the print statement.
If you want to change the header information then this is the first thing
send back to the client. When sending white spaces, using echo's or print
statements the header information is automatically send. The message:
"Warning: Cannot send session cache limiter - headers already sent" is
telling you did send something before using the header function. it is even
telling you where you did this (hence the line "/devel/joinnow.php on line
20").

I don't know where you got your suggestions or other information from the
internet but www.php.net is a good place to start. Look at
http://www.php.net/manual/nl/function.header.php first ;-)
HTH rob

Jul 17 '05 #6
"Lochness" <s1******@hotmail.com> schrieb im Newsbeitrag
news:ac**************************@posting.google.c om...
Thank you so much guys!!
After reading your replies I created a little test. With my template I
created a one statement page and at the top added:
--------------------
<?php error_reporting(E_ALL);?>

<?php
header("Location: test2.htm");
?>
--------------------
Notice the white space between the two php statements. I sent it up
to my server and it crashed. So I took out the whitespace, sent it up
to my server and it worked!! Then on my big program, I took out all
the blank lines and commented out the print statement. Tada! It
worked!! So thanks to you guys and grrrr to php and it's tightass
attitude towards whitespace.

It worked on my localhost which is version 4.3.4 and the server is
4.2.3. Maybe the newer version isn't as anal about whitespace.

Anyways. Thanks again!!


I am not understanding everything about that stuff, but I am quite sure that
your problem is not about PHP but about HTTP. HTTP headers can't be sent
after any output, regardless of what technique you use to send them. So if
you do this:

<?php
// PHP code
?>

<?php header("myheader"); ?>

you output white space via HTTP (and thus send the headers) in an area that
is not controlled by PHP.

If you do this:

<?
php echo "something";
header("myheader");
?>

your output is also sent via HTTP. I am quite sure that a clean arrangement
of the code in most cases solves that problem easily. For login or session
stuff I usually do it the way:

<?php
// handle session, check login, send cookie or whatever
$loggedin = "no"; // set variable with the result of the above actions
$message = "Wrong password, try it again!"; // set message according to the
above actions
?>
<html>
<head></head>
<body>
<?php
if($loggedin=="no") {
echo $message;
// display loginform
}
else {
// display contents
}
?>
</body>
</html>

Maybe your task is different, but you see the principle.

HTH
Markus
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: vivek9856 | last post by:
I am making a website and I need help promptly. Here is the code first off -----File Header.htm----- <HTML> <HEAD> <TITLE>Black Hawk Down</TITLE> </HEAD> <LINK REL=stylesheet...
4
by: Gary Hughes | last post by:
Hi all, sometime I posted a problem in here where I was getting the following error from the linker in VS C++ 2003. Linking... GCClass.obj : error LNK2022: metadata operation failed (80131188)...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
0
by: Evandro Klen S. Azeredo | last post by:
Hi, I'm with the folowing problem: I have two tables: header(id_header) and Itens(id_header, id_item). When I insert data in Itens table, this error is returned: "You cannot add or change a...
17
by: so many sites so little time | last post by:
all right so the script is pretty simple it goes it retrives what the id of the post is and it lets you edit it well no it doesnt. now if you go to www.kirewire.com/pp2/index/php you will see a...
5
by: choudhary.poorva | last post by:
I am new to C programming and learning Commands on Unix for my exam on Interprocess communication. I would appreciate if anyone can explain the following command: int chmod ( const char *...
3
by: Alami | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.