Jump to content

PHP "require" command


Guest jtpennington
 Share

Recommended Posts

Guest jtpennington

I'm grateful W3Schools has a forum for novice webmasters like myself. Hello everyone, it's good to meet you.Getting straight to the point, I'm trying to create an index.html file for my website that has four tables: a header, a navigation menu (left), main space (right), and a footer. I have read the PHP Include Files section on W3Schools, but I'm still having some trouble getting my index file to recognize my footer. Here is my footer.html file's code:

<html><head><meta name="GENERATOR" content="Microsoft FrontPage 5.0"><meta name="ProgId" content="FrontPage.Editor.Document"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>www.jtpennington.com :: The Sky Is the Limit</title></head><body text="black" alink="blue" vlink="blue" link="blue"><table border="0" width="38%" height="7%"> <tr>  <td><p align="center"><a href="http://www.jtpennington.com">Home</a> | <a href="http://jtpennington.com/webmail/">Webmail Login</a> | <!For Temporary Use, Use Journal... Make this better later.><a href="http://jtpennington.com/journal/?page_id=2">About Me</a> | <a href="http://www.jtpennington.com/contact_me.html">Contact Me</a></p></td> </tr></table></body></html>

I also have the file as a PHP, because I didn't know if you had to use a "footer.php" file since I was using a PHP command.Here is the footer.php code:

<html><head><meta name="GENERATOR" content="Microsoft FrontPage 5.0"><meta name="ProgId" content="FrontPage.Editor.Document"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>www.jtpennington.com :: The Sky Is the Limit</title></head><body text="black" alink="blue" vlink="blue" link="blue"><table border="0" width="38%" height="7%"> <tr>  <td><p align="center"><a href="http://www.jtpennington.com">Home</a> | <a href="http://jtpennington.com/webmail/">Webmail Login</a> | <!For Temporary Use, Use Journal... Make this better later.><a href="http://jtpennington.com/journal/?page_id=2">About Me</a> | <a href="http://www.jtpennington.com/contact_me.html">Contact Me</a></p></td> </tr></table></body></html>

As you will notice, it's the exact same code. I don't know which file to use.This is the code for my index.html file, the first page that my server resolves to my domain.index.html code:

<html><head><meta name="GENERATOR" content="Microsoft FrontPage 5.0"><meta name="ProgId" content="FrontPage.Editor.Document"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>jtpennington.com :: The Sky Is The Limit</title></head><body>This is a test to include the footer into the index page...<?php require("http://www.jtpennington.com/footer.php"); ?></body></html>

I have tried the directly above index.html file exchanged for a different file, "http://www.jtpennington.com/footer.html" but that did not work either.I am asking what I am doing wrong for including data from other files so that my index file could include my footer, my navigation menu, and my header. What exactly is the use of the "require" function, and what does the "include" function do? Why are there 2 such commands for PHP?

Link to comment
Share on other sites

rename index.html to index.phpUnless you use .htaccess to tell .html pages to excute php code, you'll have to make your page index.php Then, and only then will the PHP be excuted on the server.If you'd rather allow .html pages to excute PHP then create a .htaccess file and put this in it, then upload it to your webspaceRewriteEngine OnAddType application/x-httpd-php .htmlYou'll have to make sure that your host allows you to use .htaccess fileNow to answer your "require" vs. "include" questionIf you include a file and for whatever reason it doesn't load, has an error on it, or doesn't exist then you'll get "warnings" on your site but it will STILL load the rest of the site.If you require a file and the above happens (doesn't load, etc.) then NOTHING on the page will loadBy the way, why add <head> and all those other tags in your footer file?when you require/include it, you'll just end up with duplicate <head> etc. tags.The file you which to require/include should just have the basic code you want added.Out of everything in your footer file, this is all that should be there:

<table border="0" width="38%" height="7%"><tr> <td><p align="center"><a href="http://www.jtpennington.com">Home</a> | <a href="http://jtpennington.com/webmail/">Webmail Login</a> | <!For Temporary Use, Use Journal... Make this better later.><a href="http://jtpennington.com/journal/?page_id=2">About Me</a> | <a href="http://www.jtpennington.com/contact_me.html">Contact Me</a></p></td></tr></table>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...