homepage Welcome to WebmasterWorld Guest from 54.196.168.78
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Questions about Combining HTML/PHP
pigsinpink




msg:3395462
 2:31 am on Jul 16, 2007 (gmt 0)

Hi, I'm a newbie to PHP. My only knowledge is in using HTML. I'm planning on doing SEO for a new site, put up Adsense and publish it.

Ideally, I'd like to use my existing HTML skills and add snippets of PHP codes that I've just learnt. I know there is a steep learning curve, so I plan to take it step-by-step. However I do have some questions about PHP and here they are:

1) Is PHP well supported with browsers like IE 6-7, Firefox 1-2, and Safari, and Opera?
2) Will there be any conflicts in using stylesheets to control HTML tags?
3) Is it better to use SSI or PHP's include command?

Appreciate your feedback.

 

Gian04




msg:3395473
 2:58 am on Jul 16, 2007 (gmt 0)

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?

No

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]

chuckstarks




msg:3397442
 8:54 pm on Jul 17, 2007 (gmt 0)

PHP is really a dynamic page generator. You can hide the use of PHP from browsers with the following in the php.ini file

expose_php=Off

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 ...>
Sethandler application/x-httpd-php
</FilesMatch>

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.

londrum




msg:3397452
 9:00 pm on Jul 17, 2007 (gmt 0)

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.

pigsinpink




msg:3397952
 9:57 am on Jul 18, 2007 (gmt 0)

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:

website.com/php/header.php
website.com/php/footer.php
website.com/php.copyright.php
etc...

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?

HarryM




msg:3397966
 10:30 am on Jul 18, 2007 (gmt 0)

You can reference the file to be included in several ways, e.g.

<?php include("website.com/php/header.php");?>

<?php include("../php/header.php");?>

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.

<?php require("website.com/php/header.php");?>

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.

<?php require("website.com/includes/header.inc");?>

HarryM




msg:3398364
 5:43 pm on Jul 18, 2007 (gmt 0)

website.com/php/header.php
website.com/php/footer.php
website.com/php.copyright.php
etc...

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.

page.php

<?php
$title = "Page title";
$descrip = "Page meta tag description";
$keywords = "kw1 kw2 kw3";
$content = <<< eof
Page-specific content goes here
eof;
// $content can include text, HTML tags, images, etc.
// You can also use full quotes.
require("www.domain.com/includes/template.inc");
?>

template.inc

<?php
// 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<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" />
</head>
<body>
<!-- HTML -->
<?php print $content;?>
<!-- HTML -->
</body>
</html>

pigsinpink




msg:3398876
 10:02 am on Jul 19, 2007 (gmt 0)

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?

WesleyC




msg:3399115
 3:02 pm on Jul 19, 2007 (gmt 0)

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]

pigsinpink




msg:3399619
 12:54 am on Jul 20, 2007 (gmt 0)

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.

jatar_k




msg:3399842
 10:01 am on Jul 20, 2007 (gmt 0)

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.

WesleyC




msg:3399933
 1:18 pm on Jul 20, 2007 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved