OMFG.

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

OMFG.

Post by m3mn0n »

This really got on my nerves. I had a very simply email job to do and I couldn't figure out what was wrong. :roll:

For developing PHP for more than a year now, I was disapointed in myself...heh. Here is a mock up of the structure of the script:

Code: Select all

<?php
// check if submit was sent via request method, if not shout error msg

// check to see if email address is valid, if not send to error pg via header()

// check to see if variables are set, if not send to error pg via header()

// set variables for mail and trim incoming variables

// send email, if it was sent, it forwards a user to a thank you page via header(), if not sends to error pg via header()
?>
Now I was playing with this script forever, revision after revision, and the email checker and variable checker portions of the script were not functional AT ALL.

After about the 10th rewrite of the entire script, I tested something out; instead of forwarding to a thank you page, i would add phpinfo() to see what the settings of the server were.

I added jibberish to the fields thinking it wouldn't matter, and then submit the form. Low and behold; It starts to work. I was puzzled. I didn't even bother to anylize the phpinfo() page, i just re-added the header() function that sends to a thank you page; and tried again.

ERROR! I didn't work. This freaked me out. I went ahead and re-added phpinfo() and tested again. It worked!

Angry, frustrated, and happy all at once i went ahead and added require("thankyoupage.html") instead of the header() forwarding it there. And it works like a charm now.




Now my question is; why did it ignore an entire portion of my script because of that header() function? I've never heard of a problem like this before so I hope some of you veterans can clear this up for me.



btw: the original script worked perfectly on my testing server which runs php 4.1.1. Site that this all happened on has 4.2.3. This script has no HTML on it, it's pure PHP.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

wow...nobody has seen anything like this before? :(
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

hmmm

Post by evilMind »

well, w/o seeing any code it's not suprising that nobody has responded. It's hard to shoot a deer in the dark. However, I'll be the lucky .. person .. to *attempt* at answering your question.

1) did you have a exit(); or die(); call after the header() call?
2) is the header() call a valid call or is it bailing out because it's not valid?
3) are the headers for the page already sent? try using
if ( !headers_sent() ) {
header('Location: somepage.html');
exit();
} else {
echo "AHH! It's because the headers are already sent!!!";
}
4) if the headers keep getting sent for some reason try turning on output buffering. ob_start(); ...code... ob_flush();
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Re: hmmm

Post by m3mn0n »

evilMind wrote:well, w/o seeing any code it's not suprising that nobody has responded.
I shouldn't need to post the code. The comments describe what is happening and it's pretty easy to paint a mental picture of what is going on in the script.

There is no HTML headers on that page, like I said. Also no headers are being parsed on the page unless there is an error within the code as the comments describe.

I figured this is one of thoses rare little things about the syntax that I didn't know, or something having to do with my php version or a setting...

Thanks for the lovely responce. :roll:
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

curious... how curious.... hmmmmmmmmmmm
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Re: hmmm

Post by jason »

Sami wrote:
evilMind wrote:well, w/o seeing any code it's not suprising that nobody has responded.
I shouldn't need to post the code. The comments describe what is happening and it's pretty easy to paint a mental picture of what is going on in the script.
It's been my experience that comments and code are two completely different things. By showing us the comments, you show us what you intended the program to do. The code shows us what you told the program to do. Two completely, completely, 100% completly different things.

My guess, from what I have seen, is that there is an error in the logic in your code. But to give you an accurate answer, I would need to see the code.

:D
unixchick
Forum Newbie
Posts: 11
Joined: Thu Sep 11, 2003 11:21 pm

Post by unixchick »

omfg, post the code... :wink:
lol, serriously

Coders minds are like parsers, they ignore the "//" comments
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

I can agree with Jason and UnixChick.... ahem apart from one having cool pic as avatar and other says about "CHICK".. ;)..

seriously.. if that's not a code you have written for CIA or FBI, that should be kept confidential..lol... you should show it to us... maybe then only you can get some logical answer... and then maybe you will say ..., " OMFG, there was that thing... now I know !!!"
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

igoy, maybe it's like......

If I tell you, then I would have to kill you. *puts on sun glasses* :D.

LOL

*ahem*. Okay, sorry, I'm getting a little off topic.

-Nay
Post Reply