Forum Moderators: coopster

Message Too Old, No Replies

New to web design and have a few php questions

         

Justin_L

6:30 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



I've been doing lots of research the past few weeks(most of it here) and want to design my first site the best way I can from the get go to prevent any headaches further down the road.

I modified a 2 column layout(left nav bar, right content) with header and footer that I found on the net(I checked first and it is allowed to be used for personl/commercial use).

What I want to do is create a template of sorts so that when I add new links to the nav bar, I don't have to manually update dozens of pages, and although I believe I have a firm grasp of HTML and CSS, php is completely new to me, so here's my questions.

1) If I use php, do all of my pages have to end with .php instead of .html? If so, will it just be .php or will extra stuff like? get added after the extension?

2) To use "includes" in my .php document, they all have to reside in an "includes" folder in the root of my site?

3) Are there any issues with .php includes and css layouts? Or do I just replace what I have in my .html file with

"<?php
include 'includes/header.php';
?>
"<?php
include 'includes/navbar.php';
?>
"<?php
include 'includes/footer.php';
?>"

Also, I would need a footer,php, header.php, and navbar.php in my "includes" folder?

4) If the above works correctly, all I would have to do is replace my content and then do a "save as" with a new file name?

5) Will designing my site this way have any negative affect on the Google bots for indexing?

I know these are pretty basic questions for most of you but hey, I gotta start somewhere! I just want to have my site ready to go before I buy my first domain and get a host(which supports php of course).

Thanks for your help.

DanA

8:07 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



1) yes, you have to use .php (some hosts use .php3 or .php4)
2) no, you can have your included files anywhere
3) no problem, includes are just as cut and paste
4) you will also have to modify the links within each page or use .htaccess
5) you may have to provide a .html site map as some bots do not follow php with variables, sessions...

Timotheos

11:09 pm on Jan 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) If I use php, do all of my pages have to end with .php instead of .html? If so, will it just be .php or will extra stuff like? get added after the extension?

Assuming Apache here... A lot of hosts allow you to have an .htaccess file so that any extension can be parsed for php. All you have to do is put this line in your .htaccess file.

AddType application/x-httpd-php .html

Salsa

12:50 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Justin, you're taking a wise approach to this. By figuring out all of the requirements of your site before shopping for a host, you'll be able to choose a host that meets your requirements. For example, as Timotheos said, you can make PHP parse files with any extension you wish IF your hosting server will permit it--either via .htaccess or httpd.conf (on Apache). Many will, and I wouldn't even consider a host that didn't!

When setting up which file extensions will be parsed, however, be aware that all files with the specified extensions will be parsed whether they contain PHP code or not. So, for example, if you've set up .htaccess to parse .html files and you have some straight HTML files on your site that have no PHP in them, even they will be parsed, and that can cause some unnecessary overhead. A scheme for getting around this would be to parse .htm files, but not .html files, or vice versa. If you want, you can even parse your .css files--which would allow you to include a config.inc.php page where you've defined constants for all your colors, fonts, etc. in one place.

As for which and how many files to have in your "include" folder, rather than having a bunch of separate files, like footer.php, header.php, and navbar.php..., I find it simpler to have just one common.inc.php file that contains functions that are common to all pages. There you might define functions like

function html_header(){...}
, your database connection/error handling functions, etc., all in one file. Include that just once, then simply call
html_header()
, etc., where you want the code displayed.

Back to your first question, which also relates to your fifth: The only query strings that will show up in your pages' urls will be what you purposefully put there. The exception is if you register PHP session variables. Then you may have to deal with a session id appearing in the query string. Otherwise, using PHP to create your HTML code should have no negative effect on how search engines perceive your site.

I hope this helps.

Justin_L

2:30 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Awesome, thanks everyone.

I don't think I would need to parse html files, it's not going to be a huge site(not at first anyway). It doesn't matter to me either way what the extension is, was just curious really. But it all makes sense now, how would the server know to parse the file if it didn't have a .php extension? Guess I could have figured that one out :)

Putting my header, footer, and nav bar all in a single include is a great idea, thanks.

Couple more questions. Let's say this is the html code for my "footer".

<div id="footer">
<p>
Footer here
</p>
</div>

Can I include the div tags in my "footer.php" file? Is there any benefit or downside of doing that? Or is it safer to leave the div tags alone and just put the <p> tags in my "footer.php"?

Is there a big difference between an "include" statement and a "require" statement? I was reading a begginer tutorial on another site and they used the "require" tag.

Salsa

3:15 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



how would the server know to parse the file if it didn't have a .php extension? Guess I could have figured that one out :)

That's what Timotheos explained. In the root directory for your site, put the line he showed you in a file named .htaccess (on Apache). .htaccess files have many other uses, so when shopping for a host consider making it a requriement that your host supports them.

As for what code you can include in your navigation functions, like your "footer," absolutely include whatever you need in order to render the html output that you want. Also, it will surely be worth your time to browse through the forum library [webmasterworld.com] to find solutions to many of your needs--including answers to questions that you haven't yet thought to ask!

Another invaluable resource is the PHP Manual [us2.php.net]. It's very easy to navigate and defines specifics like most tutorials won't; e.g., look up require [us2.php.net], and it explains right off the bat:

require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error...

I wish you well.

Justin_L

3:32 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Thanks again Salsa, you've been a big help.

I'll probably sign up with a host a week earlier than I had planned on just to give me enough time to mess around with php a bit before I go live.

Salsa

4:06 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



This PHP Host Directory [phphosts.codewalkers.com] might help you sort out which hosts offer what.

Mods: php.net used to house this directory, and I think they still provide a link, so I hope it's not against tos to post the url. If so, sorry!

Justin_L

6:24 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Thanks for the link. I'll be getting a host sooner than I thought!

We use an OS X Server here at work for our file server, it doesn't run anything else. So today I turned on Web Services and enabled php(it came preinstalled!), threw my index.php, includes folder, and style sheet into the web server directory and much to my surprise, my page actually works. Now to just pump out some content pages....

Thanks again to everyone, 95% of the stuff I've learned has been from this forum.