php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9041 Extra #! at top of web output.
Submitted: 2001-01-31 17:52 UTC Modified: 2002-01-20 19:03 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: john at cdproc dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.4pl1 OS: Solaris 7.
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: john at cdproc dot com
New email:
PHP Version: OS:

 

 [2001-01-31 17:52 UTC] john at cdproc dot com
Hello.

I'm running PHP4 as a CGI under Netscape Enterprise.

It's compiled with:
'./configure' '--prefix=/opt/php' '--with-config-file-path=/opt/php/etc' '--disable-pear' '--enable-discard-path' '--with-mysql=no' '--enable-trans-sid' '--with-oci8=/opt/oracle/8.1.7'

Whenever I call a .cgi that has the #!/path/to/php syntax at the top, the output always has a '#!/path/to/php' line at the top.

--- snip ----
#!/opt/php/bin/php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head><STYLE TYPE="text/css"><!--
A { text-decoration: none; }
--- clip ----

My php.ini is pretty default. There's no doc_root specified when this happens.

I would think that PHP wouldn't want to include this extra line.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-05 16:08 UTC] john at cdproc dot com
The retarded thing about this is that the EXACT SAME binary works fine when Apache calls it as a CGI. A simple /bin/sh CGI on both machines works correctly.

I'm out of clues.
 [2001-02-05 16:12 UTC] jmoore@php.net
This is caused by the fact that the #! is not inside <?php tags and thus isnt parsed by PHP, perhaps we can introduce a command line arg that ignores #! on the first line of a file perhaps

php -c

I dont think there is a special case yet atleast this certainly points to the fact there isnt.

James
 [2001-02-05 16:12 UTC] jmoore@php.net
This is caused by the fact that the #! is not inside <?php tags and thus isnt parsed by PHP, perhaps we can introduce a command line arg that ignores #! on the first line of a file perhaps

php -c

I dont think there is a special case yet atleast this certainly points to the fact there isnt.

James
 [2001-02-05 16:21 UTC] jmoore@php.net
it is in there.. My bad must be somthing else..

James
 [2001-02-05 16:34 UTC] john at cdproc dot com
Here are the CGI's I'm using:

----
#!/opt/php/bin/php
<? phpinfo(); ?>
----

----
#!/bin/sh
echo Content-type: text/html\\n\\n;
echo "foo!"
----

Now this might not help any, but I truss'd the web server process (Netscape, remember.) and here a few snippits output.

sh CGI.
read(23, " C o n t e n t - t y p e".., 8192)    = 31
send(17, " H T T P / 1 . 1   2 0 0".., 118, 0)  = 118
send(17, "\n f o o !\n", 6, 0)                  = 6

PHP CGI.
read(22, " X - P o w e r e d - B y".., 8192)    = 5120
send(17, " H T T P / 1 . 1   2 0 0".., 146, 0)  = 146
send(17, " # ! / o p t / p h p / b".., 5065, 0) = 5065

Graphic for PHP CGI page.
send(19, " H T T P / 1 . 1   2 0 0".., 146, 0)  = 146
send(19, " G I F 8 9 a82\0 C\0D5FF".., 2962, 0) = 2962

I can't tell if the web server is inserting this line or if PHP is. However, when I run these two CGIs on the command line, I never see this extra line. I guess I'm thinking that PHP does weird shit when it's not run in a shell.

Any other information I can provide?
 [2001-02-24 12:06 UTC] jmoore@php.net
Suspending this until a decision about what should be the correct behaviour from PHP should be.
 [2001-05-09 11:40 UTC] john at cdproc dot com
Here's a quick and dirty fix.

18:39 <james``> oK open cgi_main.c
18:39 <james``> and goto line 720
18:40 <james``> See that else if .....
18:40 <james``> } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) {
18:40 <james``> make it read }
18:41 <james``> and then loose the } 11 lines down
 [2001-06-17 04:41 UTC] jmoore@php.net
This will be fixed when we split the commandline and cgi modules apart. moving back to analysed.

- James
 [2001-08-31 11:53 UTC] sander@php.net
Diff copied from #8898:

*** sapi/cgi/cgi_main.c.origSun Dec  3 02:09:13 2000
--- sapi/cgi/cgi_main.cWed Jan 24 16:39:34 2001
***************
*** 719,725 ****
  return FAILURE;
  }
  file_handle.filename = argv0;
! } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) {
  /* #!php support */
  c = fgetc(file_handle.handle.fp);
  if (c == '#') {
--- 719,726 ----
  return FAILURE;
  }
  file_handle.filename = argv0;
! }
! if (file_handle.handle.fp && file_handle.handle.fp!=stdin) {
  /* #!php support */
  c = fgetc(file_handle.handle.fp);
  if (c == '#') {
 [2002-01-20 19:03 UTC] edink@php.net
I have applied the patch to the current CVS.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 09:01:27 2025 UTC