|Is PHP well supported with browsers like IE 6-7, Firefox 1-2, and Safari, and Opera? |
Yes, for as long as PHP is supported by your host.
|Will there be any conflicts in using stylesheets to control HTML tags? |
|Is it better to use SSI or PHP's include command? |
Not sure but I always use include command
Basically, as far as I understand PHP, its a just the same as HTML it just that it will allows you to create dynamic pages, plus you will be able to control a lot of things, let say you want to display a certain content to your visitor if he is using IE, but will display a different content is he is using FF. Then display a different content if he is from US compared to the content of visitors from Asia. Plus, plus plus...
[edited by: Gian04 at 3:04 am (utc) on July 16, 2007]
PHP is really a dynamic page generator. You can hide the use of PHP from browsers with the following in the php.ini file
If you use Apache you can run PHP on specific HTML/XHTML/XML files with
LoadModule phpX_module path-to-libphpX.so
<FilesMatch A.html¦B.html¦C.html ...>
You'll want to put the <FileMatch ...> in each virtual server.
Doing both allows you to hide PHP from your users completely. As far as they're concerned it's just another web page. They don't know it's a dynamic web page create with php.
your server will process the PHP before it sends the page to the visitor. so your visitors will only ever see the end product - the HTML.
as long as your server is set up to serve PHP correctly you don't have to worry about what browser people are using.
the only way they would get to see the underlying PHP code is if you messed up the server settings.
Thanks guys I've learnt quite abit and I think I'm on the right track with PHP. A question about the PHP require function. Given the following files:
1) How do I reference these files? Do I type out the full path everytime or is there a shortcut?
2) Which require command do I use - require (); or require_once ();
3) I saw the following command in another post for referencing a file.
include($_SERVER['DOCUMENT_ROOT'] . '');
Can this command be used as a short cut to reference the PHP folder mentioned above? If it is how do I reference the files? Is there a require version for it?
You can reference the file to be included in several ways, e.g.
You can use "require" instead of "include" which saves a little processing time because (I believe) the syntax of the include is not checked every time it is called.
It is common practice, but not essential, to name all includes as .inc. E.g. It also might be best to avoid the term "php" as a directory name.
I personally think it is simpler to keep all the html in one template file. Then in each page you only have to specify the page specific items as php variables. You can then change the layout of the entire site by tweaking the html in the template and the css stylesheet.
The example below is a much-simplified version of what I use. I also use other variables to specify such things as alternative indexes, whether or not to display ads, etc. It's similar to a database system except I am using flat files.
$title = "Page title";
$descrip = "Page meta tag description";
$keywords = "kw1 kw2 kw3";
$content = <<< eof
Page-specific content goes here
// $content can include text, HTML tags, images, etc.
// You can also use full quotes.
// set default for variables (in case one gets forgotten!)
if (!isset($title) ) $title = "";
if (!isset($descrip) ) $descrip = "";
if (!isset($keywords) ) $keywords = "";
if (!isset($content) ) $content = "";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php print $title;?></title>
<meta name="Description" content="<?php print $descrip;?>" />
<meta name="Keywords" content="<?php print $keywords;?>" />
<link href="www.domain.com/css/styles.css" rel="stylesheet" type="text/css" />
<!-- HTML -->
<?php print $content;?>
<!-- HTML -->
Last question ; )
If the file to be referenced in the include/require command is written in html, should it be saved as .html or .php?
It doesn't matter what the included file type is--anything between <?php and?> will be parsed as PHP, and everything else will be sent to the browser, just like a .php--as a matter of fact, I actually use .tpl (for "template") as a file extension for my included templates, then set up IIS or Apache (depending on what the system type I'm running on) to block web access to .tpl files so people can't access the templates directly (which can break your page and cause PHP errors).
Just to reiterate: the file extension of an included file doesn't matter; the contents of an included file are run as if the extension was .php.
Please though, for the sake of whoever may need to work on the site in the future (including you ;)), make sure the extension accurately reflects the content type of the file!
[edited by: WesleyC at 3:03 pm (utc) on July 19, 2007]
|Just to reiterate: the file extension of an included file doesn't matter; the contents of an included file are run as if the extension was .php. |
Are you sure about this? I saw a tutorial that said everytime you use the include/require file, PHP will by default read and treat that file as HTML - even if the file extension was saved as .php. He goes on to say that you should name the file as .php and use the <?php?> tag if the file contains php codes.
to be honest I am not sure the extension matters at all since the parser should already be going as the file doing the including is being parsed.
It is good to have a parsed extension on an included file so that if the included file is called directly people will not see the source.
As far as parser tags go it may depend on where in the including file you call it. I do believe though that I use parser tags in included files all the time. It's one of those things I never think about until someone asks.
What I meant by my post was that the included file obeys all the rules of a .php file. Whatever's contained in <?php?> tags will be run, anything else will be echoed to the browser just as it was in the original .php file.