|
Posted by Koncept on 12/01/06 23:12
In article
<doraymeRidThis-67FEB3.12591801122006@news-vip.optusnet.com.au>,
dorayme <doraymeRidThis@optusnet.com.au> wrote:
> Following my last post, a bit further progress. I had trouble
> starting the server after making changes and discovered I had
> uncommented in the last block at bottom (the one you thought I
> might not have at all) what I probably should not have - real
> comments! I had misunderstood. It _was_ just as your supplied
> text and so I now leave it as is. I have been able to restart the
> server (I do it via the Sys Pref panel). If I use .php in html
> file name, it has a good go at it now! But it cannot find the
> includes folder.
>
> I have things working fine after various efforts on a remote
> commercial server. But it is the local server on this machine of
> mine I want it now to work on.
>
> I summmarise 2 outstanding problems:
>
> (1) I use the following code in the includes:
>
> <?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc');
> ?>
>
> but this stumps my server.
>
> (2) I want for the engine to look at all .html files (for now, I
> do not want to use .php). On my remote commercially hired
> servers, I think I used a .htaccess file to achieve this. Shall i
> do this on local machine or surely there is a more elegant built
> in way?
>
> I would appreciate help to solve these two outstanding probs.
Okay.. So I assume that you have php working now. Just to give you a
few tips... The server root is /Library/WebServer/Documents; however,
you also have a user-based directory which is located at
/Users/*YOU*/Sites. Choosing either of these will work, but I prefer to
use the first for all my development.
Next.. If you are not familiar with UNIX or shell commands, you can
start and restart the server from System Preferences > Sharing >
Services > Personal Web Sharing. This starts and stops the Apache
server. Let's keep things simple and start and stop from here from now
on.
Your personal computer can be located in a browser via http://127.0.0.1
or http://localhost or http://*your**IP**Address*. If you are using
the *Sites* directory to create and maintain your sites, you would
append a tilda ~ to the URL. Like this http://localhost/~*username*.
If you create a plain text file with the following contents
<?php phpinfo() ?>
and save this file in /Users/*you*/Sites/index.php when you open your
browser up to http://localhost/~*you*/ you should see a whole mess of
stuff about PHP. If this works, you have PHP enabled and working on
your system properly.
$_SERVER['DOCUMENT_ROOT'] will point to /Library/WebServer/Documents by
default, so make sure that the file you are including exists where you
are trying to include it.
To see the $_SERVER superglobal details, paste this into a file and
call it in your browser
<?php printf("<pre>%s</pre>",print_r($_SERVER,true)); ?>
You can also test for the file to include using something like this.
There are many ways to do this... This is just one.
<?php
$inc = $_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc';
if( is_file( $inc ) ) include( $inc );
else die( "Include file not located where specified" );
?>
There really is no need here to use die, because if the include file
you are trying to import is essential to the functionality of your
script, you would use *require* - a call which would cease
functionality of the script if the include could not be processed. By
default, if *include* cannot process the include file, a warning will
be triggered.
With regards to question 2, there are many ways to do this, but I think
having the server look at all .html files as server-side files is
making things a lot slower than they have to. Is there a particular
preference apart from preference why you wish to only use .html? You
can solve this with .htaccess or within the httpd.conf file ( if you
have access to it ).
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Navigation:
[Reply to this message]
|