help in using the php include
Moderator: General Moderators
help in using the php include
I am wanting to use the "PHP Include" to link a left column file to all the different web pages.
I have checked many forums for the proper code and I still can't get it to work.
I'm new to coding with php, doing many HTML & css.
Any help would be great.
Thanks in advance.
URL's to files
http://www.cowichanmen.org/westcoastmen.org/indexw2.php
URL for php include file
http://www.cowichanmen.org/westcoastmen ... olumn.html
Coding:
<!-- end #header --></div>
<!--lftcolumn -->
<?php include(“www.cowichanmen.org/westcoastmen.org/lftcolumn.php”);?>
<!--lftcolumn -->
<div id="mainContent">
-----------============---------==============----------
Not sure whether I need to include the div's for the sidebar
<!-- end #header --></div>
<div id="sidebar2">
<div id="sidebar1">
<!--lftcolumn -->
<?php include(“www.cowichanmen.org/westcoastmen.org/lftcolumn.php”);?>
<!--lftcolumn -->
<!-- end #sidebar1 --></div>
<!-- end #sidebar2 --></div>
<div id="mainContent">
I have checked many forums for the proper code and I still can't get it to work.
I'm new to coding with php, doing many HTML & css.
Any help would be great.
Thanks in advance.
URL's to files
http://www.cowichanmen.org/westcoastmen.org/indexw2.php
URL for php include file
http://www.cowichanmen.org/westcoastmen ... olumn.html
Coding:
<!-- end #header --></div>
<!--lftcolumn -->
<?php include(“www.cowichanmen.org/westcoastmen.org/lftcolumn.php”);?>
<!--lftcolumn -->
<div id="mainContent">
-----------============---------==============----------
Not sure whether I need to include the div's for the sidebar
<!-- end #header --></div>
<div id="sidebar2">
<div id="sidebar1">
<!--lftcolumn -->
<?php include(“www.cowichanmen.org/westcoastmen.org/lftcolumn.php”);?>
<!--lftcolumn -->
<!-- end #sidebar1 --></div>
<!-- end #sidebar2 --></div>
<div id="mainContent">
Re: help in using the php include
You can just use a relative path.
Your link at the top points to a .html file but the filename referenced in your code examples is a .php file.
Code: Select all
include 'lftcolumn.php';Re: help in using the php include
Actually I had a copy of both, wondering if it made a difference. Still can seem to see it recognizing the file.
Thanks for your help
Thanks for your help
Re: help in using the php include
These are the warnings I got.
Warning: Division by zero in /home/cowi5783/public_html/westcoastmen.org/indexw2.php on line 64
Warning: include(“wwwcowichanmenphp”) [function.include]: failed to open stream: No such file or directory in /home/cowi5783/public_html/westcoastmen.org/indexw2.php on line 64
Warning: include() [function.include]: Failed opening '“wwwcowichanmenphp”' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cowi5783/public_html/westcoastmen.org/indexw2.php on line 64
This last line --> (include_path='.:/usr/lib/php:/usr/local/lib/php')
I'm not sure what this means, but could that be part of the problem if I'm not on a windows server?
Thanks
Warning: Division by zero in /home/cowi5783/public_html/westcoastmen.org/indexw2.php on line 64
Warning: include(“wwwcowichanmenphp”) [function.include]: failed to open stream: No such file or directory in /home/cowi5783/public_html/westcoastmen.org/indexw2.php on line 64
Warning: include() [function.include]: Failed opening '“wwwcowichanmenphp”' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cowi5783/public_html/westcoastmen.org/indexw2.php on line 64
This last line --> (include_path='.:/usr/lib/php:/usr/local/lib/php')
I'm not sure what this means, but could that be part of the problem if I'm not on a windows server?
Thanks
Re: help in using the php include
That last line is the include path; it's where PHP looks for files specified by the include function.
Did you change the include command as per my previous comment? The errors you've posted suggest otherwise.
Did you change the include command as per my previous comment? The errors you've posted suggest otherwise.
-
Amanda1998
- Forum Newbie
- Posts: 23
- Joined: Tue Dec 13, 2011 10:25 am
Re: help in using the php include
Are you including from same server ?... or external source ...?
If you are trying to include a php script from another site, either that the remote server that host the script is not given you permission to do that or that the server where you are does not give you permission for inclusion of external files...
Second, will be my guess(on the external source case), since file inclusion (from external sources) has been denied from almost every host server (security reason)
But as @Celauran said : You can just use a relative path.
Here is my way:
If you are trying to include a php script from another site, either that the remote server that host the script is not given you permission to do that or that the server where you are does not give you permission for inclusion of external files...
Second, will be my guess(on the external source case), since file inclusion (from external sources) has been denied from almost every host server (security reason)
But as @Celauran said : You can just use a relative path.
Here is my way:
Code: Select all
<?php
//begin of my code
include("path/path/path/need_file_1.php");
//body of mycode
include("../path/need_file_2.php");
// rest of the code
?>Re: help in using the php include
Thanks Amanda1998 & Celauran, your code works!!! 
So this is what I have:
<!-- end #header --></div>
<!--lftcolumn -->
<?php
//begin of my code
include("lftcolumn.php");
?>
<!--lftcolumn -->
<div id="mainContent">
URL's to files
http://www.cowichanmen.org/westcoastmen.org/indexw2.php
URL for php include file
http://www.cowichanmen.org/westcoastmen ... column.php
----------------==============---------------
Now what is happening is my css for <div id="mainContent"> is not working.
It works for HTML, but when I change it to php and add the inclose function, it seems to break the css for the <div id="mainContent">.
Any thoughts around this would be great.
Thanks for all your help
Chris
So this is what I have:
<!-- end #header --></div>
<!--lftcolumn -->
<?php
//begin of my code
include("lftcolumn.php");
?>
<!--lftcolumn -->
<div id="mainContent">
URL's to files
http://www.cowichanmen.org/westcoastmen.org/indexw2.php
URL for php include file
http://www.cowichanmen.org/westcoastmen ... column.php
----------------==============---------------
Now what is happening is my css for <div id="mainContent"> is not working.
It works for HTML, but when I change it to php and add the inclose function, it seems to break the css for the <div id="mainContent">.
Any thoughts around this would be great.
Thanks for all your help
Chris
Re: help in using the php include
your css will obviously break..
your indexw2.php page has one <html><body> </body></html>tags.. and so does your column.php
include statements bring the entire content of a file into your script.
by including column.php, you are including the <html><body> tags twice into your page.
to avoid breaking of css, you need to remove anything and everything from column.php that has already been included in the indexw2.php
your indexw2.php page has one <html><body> </body></html>tags.. and so does your column.php
include statements bring the entire content of a file into your script.
by including column.php, you are including the <html><body> tags twice into your page.
to avoid breaking of css, you need to remove anything and everything from column.php that has already been included in the indexw2.php
-
belstaffleather
- Forum Newbie
- Posts: 1
- Joined: Sat Dec 17, 2011 2:04 am
Re: help in using the php include
Thank-you all for your help.
I now have a working/validated W3C webpage.
What I learned from all this is:
Make sure your code is right
<?php
include("lftcolumn.php");
?>
& not
<?php
//begin of my code
include('lftcolumn.php');
?>
Difference " not '
In your include page,
No duplicate code that exists from your main page, including opening tags
<html>
</html>
I did find that by trying to validate it through W3C, I was able to figure out the remaining errors, once you folks got me heading in the right direction.
Again thanks for all your help.
Cheers
Final URL:
http://www.cowichanmen.org/westcoastmen.org/indexw4.php
I now have a working/validated W3C webpage.
What I learned from all this is:
Make sure your code is right
<?php
include("lftcolumn.php");
?>
& not
<?php
//begin of my code
include('lftcolumn.php');
?>
Difference " not '
In your include page,
No duplicate code that exists from your main page, including opening tags
<html>
</html>
I did find that by trying to validate it through W3C, I was able to figure out the remaining errors, once you folks got me heading in the right direction.
Again thanks for all your help.
Cheers
Final URL:
http://www.cowichanmen.org/westcoastmen.org/indexw4.php
Re: help in using the php include
Sorry, but that's incorrect. You can use single or double quotes in an include.carm wrote:What I learned from all this is:
Make sure your code is right
<?php
include("lftcolumn.php");
?>
& not
<?php
//begin of my code
include('lftcolumn.php');
?>
Difference " not '
Re: help in using the php include
I use PHP Include extensively
look at the document as a whole, and you will notice many parts are the same across my gaming site for example. http://www.hardcore-games.tk
now the banner and the menu are always present on each page
so snipped the menu from the index.php and saved it as a PHP file even tough its an HTML snippet
then I used the include function to add the block back into the document
I repeated the process for the bottom copyright and so on
in each include, there is a mix of HTML, JavaScript and PHP but the include files are always PHP simply to avoid problems
after assembly the original document is as it was before I use include
then after the index.php was looking the way I wanted, I rolled out the include to all documents
look at the document as a whole, and you will notice many parts are the same across my gaming site for example. http://www.hardcore-games.tk
now the banner and the menu are always present on each page
so snipped the menu from the index.php and saved it as a PHP file even tough its an HTML snippet
then I used the include function to add the block back into the document
I repeated the process for the bottom copyright and so on
in each include, there is a mix of HTML, JavaScript and PHP but the include files are always PHP simply to avoid problems
after assembly the original document is as it was before I use include
then after the index.php was looking the way I wanted, I rolled out the include to all documents
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
My site is powered by LAMP
-
Amanda1998
- Forum Newbie
- Posts: 23
- Joined: Tue Dec 13, 2011 10:25 am
Re: help in using the php include
Light web, easy loading... good for @Vegan
Re: help in using the php include
thanks
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
My site is powered by LAMP