Script needed???

They have: 18 posts

Joined: Jul 2004

I need to add this line:
#!/usr/local/bin/php'
to the top of PHP documents (recursively) throughout my site directory.

Unfortunately it was not as simple as I thought. I tried using tcsh syntax to rename (mv) each file with a new .bak extension, then "echo" the new line, and append the .bak file, saving the whole mumbo-jumbo as the original .php file. Sounds great, and works, but too many php documents got the inclusion.

As I came to realize, only the php files which are not included (I refer to these as "parent" files) within other php files need this addition. This is because the parent file carries this inclusion to all of its "childeren".

Any takers?

- Jeremiah D. Jinno :chef:

PS - Here is my idea on a possible pearl or shell script:

- Recursively find and make a list of all .PHP files, including their paths (PWD)
- Search document contents for include() or include_once()
- If inclusion is a local .PHP file, then that file (and directory) may be de-listed
- Files remaining get the "#!/usr/local/bin/php" inserted as the 1st line of code
- All files are saved, as is, because I dont need backups

- Jinno

-----------------------
"I hear and I forget. I see and I remember. I do and I understand." - Confucius

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

why do you need a shebang on a php file?!

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

A little Googling turns up that you need it if php is installed as cgi without the php module on Apache. Is that what's happening?

http://ca2.php.net/security.cgi-bin

There are better options.

He has: 1,758 posts

Joined: Jul 2002

I thought you only needed to do that for perl scripts?

They have: 18 posts

Joined: Jul 2004

FYI - I am trying to install and run a TYPO3 package, but my school is kinda screwy in how they deal with the PHP / Apache thing.

It all happened a few years ago, when a student user programmed himself some holes (not on purpose) that were attacked (quite on purpose) and instead of fixing the security issues of how they used to do it (IE - The server ran as a user called "nobody" and all PHP permissioning was done through that user, so that they could block/allow/deny any PHP privelidges to the entirety of the system rather than allow each individual user to be "underlings" under the rule of the SysAdmin) they simply changed the whole system so that each user is "captain of his own ship" as it were.

Anywho, thats how it was explained to me, and it just makes me have to put that stupid include in every core PHP file.

- Jeremiah

- Jinno

-----------------------
"I hear and I forget. I see and I remember. I do and I understand." - Confucius

They have: 461 posts

Joined: Jul 2003

use perl to fix the php. simple have it recursively go through your directory, open all .php files, and then read in "<?php"
insert that on the next line
then read the rest of the file, and save that.

with my base knowledge of perl i should be able to write that in about 30 min.. hmmm...i dont have anything here, but the only thing that would be any chance of challenging me because i dont already have the base for something else i wrote would be the recursive open.

do you know perl? i dont feel like writng the script, but if you know it i'll help you if you'd like

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

no no -- read the comments on the thread I linked. Show that to your college.

Also, the shebang has to be the first line.

i.e.

<?php
#! usr/bin/local/php

// your code goes here
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.