I am using wamp, and I have two directories; /www and /scripts. In /www I have index.html, and in /scripts I have test.php. I am not too familiar with standard PHP directory conventions, but here is what I would like to have in my index.html file
...html statements... <run the following php script: /scripts/test.php> ...html statements
rather than include the php script itself in the index.html file.
I have researched the ScriptAlias directive in Apache (http://httpd.apache.org/docs/2.0/mod/mod_alias.html#scriptalias) but I didn't quite understand how to apply it to this situation. Any ideas on how to proceed?
preguntado el 22 de mayo de 12 a las 21:05
You can't link to PHP outside the doc root from within HTML, but you can include PHP from outside the doc root from within PHP. I.e., replace the index.html with an index.php, that looks something like this:
...html statements... require_once '/path/to/scripts/test.php'; ...html statements...
You cannot access files outside of the document root using HTML (luckily).
Think about what can happen when someone can just access stuff outside the document root, e.g.:
/etc/passwd o lo que sea.
However if you use php you can access files outside document root by for example using:
include. And this is IMHO best practice when doing something in PHP. In your document root you will only have a archivo de arranque which accesses files outside the document root.
This is because PHP is server side and HTML is client side.
If you want to access a file 1 directory above the current directory you can you a relative path:
Can't be done with HTML, however if you had an index.php file instead of an index.html file you could do it. I guess you could setup apache to compile html as php if you have to keep it as an html file.