PDA

View Full Version : While studying my PHP I hit a rut!


tom
12-15-01, 06:52 PM
Happy Holiday!

I am working my way through 'PHP Essentials' example by
example in order to set a foundation. It's even fun sometime!

I have run into a section that I just can't figure out. I am
hoping there is an easy answer and a kind soul to provide it.

SPECIFICALLY:
- - - - - - -
The html form
- - - - - - -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">

<HTML>

<HEAD>

<TITLE>Redirection Menu</TITLE>

</HEAD>

<BODY>

<FORM method="POST" action="do_redirect.php">

<P>I want to go to:

<SELECT name="id" size="1">

<OPTION value="prima">Prima-Tech</OPTION>

<OPTION value="php">PHP.net</OPTION>

<OPTION value="slashdot">Slashdot</OPTION>

<OPTION value="linuxchix">Linuxchix</OPTION>

</SELECT>

<INPUT type="submit" value="Go!">

</FORM>

</BODY>

</HTML>

- - - - - - -
the php script
- - - - - - -

#!/usr/local/bin/php


<?php

if ($id == "prima") {

$location = "http://www.prima-tech.com/";

} else if ($id == "php") {

$location = "http://www.php.net/";

} else if ($id == "slashdot") {

$location = "http://www.slashdot.org/";

} else if ($id == "linuxchix") {

$location = "http://www.linuxchix.org/";

}

header("Location: $location");

exit;
?>

- - - - - - - - -
the error message
- - - - - - - - -

Warning: Cannot add header information - headers already sent by
(output started at /www/t/trulytimeles/htdocs/do_redirect.php:3)
in /www/t/trulytimeles/htdocs/do_redirect.php on line 23


I've made the following committment to myself -
DO NOT skip over examples that you can't get to work, figure
it out, ask someone, DON'T DO NOTHING!

Any help would be greatly appreciated.

HAPPY HOLIDAY!

sophiespo
12-16-01, 07:16 AM
Hi Tom,

Im NO PHP expert... but i got the same error message the other day. It occured because I had the #!/usr/local/bin/php line on top of a file that wasnt called directly.

The error message means that two files are sending header information to the browser, which is something you dont want.

I think this will fix it:

you shouldnt need the #!/usr/local/bin/php line on top of the php file because it isnt being called directly. Information is being sent to it via the form and based on the selection by the user it will take them to another page, which will generate headers of its own. So you wouldnt need the form to send headers.

This is logical in my mind, like I said Im no expert but try it. And let me know if it works!

sophie

tom
12-16-01, 07:15 PM
Sophie,

What you wrote made sence to me and I am VERY new at dynamics on the internet.

I removed 'the line' and received 'the 500' error - which indicates to me that your suggestion solved the 'header' challenge.

As for 'the 500' I have been uploading and testing a number of little tiny php scripts and they seem to work fine. In other words, I am using a text editor and the permissions have been set to '755'

I don't know what's wrong with this little script, but I KNOW your suggestion to think about which pages REALLY need 'the line' at the top will be profitable to me with future scripts.

I notice all the assistance you and others provide to we members. My comment to you is BRAVO and THANK YOU!

tom

Codicus
12-17-01, 12:49 AM
The error message you are getting indicates that you are trying to send HTTP header information after you've already sent some of the text of your page.

You must send any headers and cookies before you've sent any of your page text.

tom
12-17-01, 01:33 AM
Greetings,

As I mentioned I am at the beginning.

The script I am having trouble with is one that I copied out of Julie Meloni's PHP Essentials.

After reviewing your suggestion, I looked over this little script .

Perhaps when you have some time you will 'show' me where the 'mis-order' in this script has occured.

This would be most helpful to me.

Thanks for responding,

tom

IonaBusiness
12-17-01, 10:26 PM
It appears that the 500 error could be a permissions prob.
Check the error logs to see.
all php files must be 755...

goodluck, Bill

tom
12-18-01, 01:41 AM
Permissions is NOT my problem with this script, BUT YOU DID GIVE ME A GREAT ANSWER!

YES, you're right, I SHOULD be checking the error logs.

Thanks Bill, don't know if I'll understand them but it's a SUPER place to start!

COOL!

tom

wwuud
12-18-01, 06:09 AM
I am completely baffled.

I have NEVER had to put the "#!/usr/local/bin/php " at the top of ANY php files. My site is on saturn.powweb.com, if that makes any difference.
I order to prevent teh header error mentioned earlier, you MUST place the "<?php" tag as the very first bytes of the php file. anything else above that, the output of the file has started, and the headers have already been shot out. That would prevent setting session variables, cookies or redirects from happening, as they are all done in the header.

The following three lines in a file named something like "test.php" should produce a *bunch* of output containing all the configuration information:

<?php
phpinfo();
?>


That's it. 3 lines. complete script. neat test. If that does not work, complain to the admins until they fix it.

- Earl

Codicus
12-18-01, 07:09 AM
My server, mars, also allows me to use mod_php(no '#!/usr/local/bin/php' line needed). I switched over to the CGI version, with the '#!/usr/local/bin/php' junk recently however. I discovered that there is no way to protect your MySQL password from other users on the same server as you when using mod_php. mod_php requires your script to be open for reading by other users. With the CGI version you only have to make the files that are directly executed executable, not readable.

sophiespo
12-18-01, 09:52 AM
Im on venus, gotta use the #!/usr/local/bin/php lines..
its not so hard to figure out which files need them, but now ive come across a file that needs the line because it is called directly, and its also included in another file, so the #! line shows up anyway... *sigh*

sophie