Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199807

Re: [PHP3] The Basics: Getting Started with Scripts From: Richard Lynch (lynch <email protected>)
Date: 07/31/98

[I refer to <?php ?> below. It's a nice short-hand for the <SCRIPT tags you mention here.]

>1. If I understand correctly, I can put PHP code into any html file with the
><script language = "php" /script> tags and that the html file can be in any
>directory.

Yes, provided...

>2. Do I have to rename the extension to PHP3 with the CGI version. I do not
>think so since it is not going through the server.

Well, at some level it *IS* going through the server. The URL ends up being requested, and the server has to do something with it.

What you actually need to do is convince the server that you want all *.xxx files to be handed off to your php cgi, so it can do its magic and give back an answer.

This can be done in a variety of ways, but since it sounds like you are on a virtual host and your ISP isn't running PHP, so you are using PHP as a CGI, then most likely your only option is to:

Create a file named .htaccess in your web root directory.

In that file, put something like the following two magical lines:

AddType application/x-httpd-php3 php php3 phtml htm html
Action application/x-httpd-php3 /cgi-bin/php

NOTES:
#1. I *think* 'application/x-httpd-php3' is correct here. All the machine cares about is that they match. Us humans, though, prefer something that we can assign some meaning to. In this case it is saying that PHP3 is an application (program) that, errr, extends the functionality of httpd (ie, the apache server demon program)... Or, at least, that's how I [mis-]understand it. Actually, when I set mine up, I couldn't find this 'official' mime-type, so I just used 'script/php3' Works for me... :-)

#2. In line 1, I am telling the server that I want *ALL* of these to be treated as php3 files: .php .php3 .phtml .htm .html
That sounds like what you want, but you may not. You may find it less confusing to rename the php scripts with .php3, and have only php3 on line 1 of the .htaccess file above. Then your htm files will not be parsed by php, and you won't be able to put <?php ... ?> in them. The only time it would be bad to have htm in there would be if you were running a million-hits-a-day site, and lots of the files were straight htm, and having PHP parse them slowed stuff down...

Oh, if for some reason you already had php2, then you would actually have four lines. Two for php3, and two for php2. The .phtml would represent php2, and .php3 would represent php3 (duh). You can ignore this, but others reading this thread might be interested...

#3. /cgi-bin/php is where *MY* php lives. Yours may be slightly different. It would seem that as far as the .htaccess file is concerned, the current path is where you end up when you login, at least for me...

Hmmmm. Anybody want to 'splain how the .htaccess file in my web root ends up using my doc root as '.'?... I mean, how does it do this? I appreciate it, since it's actually hard for me to figure out where my cgi-bin *REALLY* lives, since my ISP gave me these nice symbolic links to everything. (ls -als rules!) But what's the overall rational for this, since I'm sure it's not just because I'm an idiot who took a month to figure out how to find out where a symbolic link *really* lives.

Full and complete (and pretty decent) documentation on this .htaccess crap can be found at www.apache.org You have to click around a lot, and take notes, because it's all disassociated, and, as always, the overview you so sorely need to put all the puzzle pieces together is sorely missed, but it's there.
The srm.conf file referenced there is a file your host has set up for all the extensions (.ram, .gif, .jpg, ...) he is supporting. You are augmenting that file with your .htaccess file. You probably can't edit his srm.conf file. :-)

>3. It isn't clear in the doc on how to interface the script with the
>cgi-bin/php files? What is being called and how? I suppose the html
>resident php code provides the script and I need to reference an interpreter
>somehow. I've seen no examples of this so I am somewhat lost.

It is rather hard to set up for somebody who is not a guru/root on a machine, and/or does not really understand how the big picture works.

Here is an excerpt from another thread which may be useful:

> Brian Schaffner <BSchaffner <email protected>> sez:

Server(apache) Client(netscape)
----------------------------------------
1) Listens for connection
                                        2) Opens socket to server's
                                        listening address:port
3) TCP Wrappers (if enabled)
4) accepts connection
                                        5) Send request:
                                        GET /index.phtml HTTP/1.0
6) (Simplified)
    Apache checks authent.
    Maps url to physical file
    Checks for handler on file's
    mime type (application/x-httpd-php3 .phtml)
    passes request through the php parser
    sends result to client
                                        7) reads response
8) closes connection
                                        9) closes connection
                                        10) parses html and displays page
                                        11) reconnects to server(s) as
                                        necessary for graphics, etc...

You can verify this by connecting to a server using telnet.
Just type something like:

        telnet www.php.net 80

After it connects, type:

        GET / HTTP/1.0

Unless you're behind a firewall, in which case you do:

        telnet firewall.mycompany.com 80

        GET http://www.php.net/ HTTP/1.0

The thing you are seemingly not understanding, and probably not doing, and which I tried to explain above is in:

6) ...
   Checks for handler on file's
   mime type (application/x-httpd-php3 .phtml)
   passes request through the php parser

This is where your .htaccess file steps in and tells the apache demon (aka 'the server' aka httpd) that you want your .php3 files parsed by the cgi located in your cgi-bin directory and named php.

>4. I've notice the pconnect for MYSQL and plan to use it for persistance
>connections even though the CGI version will not support it. I'd like to
>use this hoping I can switch over to the Apache module version sometime in
>the future. Will it function correctly closing the persistant mode with
>each request, or will it blow up?

I believe this will work...

If not, it should not be too hard to leave it as connect, and change it to pconnect when your ISP sees the light and installs PHP as module because it's just too cool not to. :-)

You'll need to remember to *remove* your .htaccess file when this glorious day occurs, since otherwise you will be over-riding the built-in PHP Module to run your lowly php cgi program, which would be inefficient, wasteful, and downright silly... I just hope you can remember this .htaccess nightmare^H^H^H^H^H^H^H^H experience as something to undo when that does happen... I doubt I will with my site. :-^

>There will be more later. Hopefully, not too much. Please keep any answers
>simple and clear for poor old dumb me to understand. Thanks...

Believe me, I can only explain this crap at all is because a few weeks ago I was way more lost than you are now. :-)

Disclaimer: I wrote this to get my own review of this material as much as for you. :-)

-- 
--
-- "TANSTAAFL" Rich lynch <email protected>

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3