The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Include footer not working
HenryH
post Feb 1 2018, 07:30 AM
Post #1





Group: Members
Posts: 3
Joined: 1-February 18
Member No.: 26,582



New to all this so please be gentle with me !

Have created a simple .php file :

CODE
<?php
echo "<p>Copyright © 2016-" . date("Y") . " Some info?</p>";
?>


The intention being to create a uniform footer for each webpage.
On the HTML file for the webpage I have the line :-

CODE
<?php include 'footer.php';?>
(OR <?php include '/footer.php';?>)

I get NOTHING included on my webpage.
What an I doing that is wrong??

Any help much appreciated.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 1 2018, 09:24 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



First check that PHP works at all, e.g. with this on the web page:

CODE
<?php echo "PHP works!"; ?>

If the above doesn't work, try using a .php extension on the web page (this is usually required by default, but can be changed to e.g. .html with a server directive).

If my echo doesn't work even with a .php extension, check that your web host allows PHP (most paid ones should do that). To run PHP on your offline computer you need special software.

If my echo above does work, check that the include file is in the correct directory (the web root in this case).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
HenryH
post Feb 3 2018, 04:25 AM
Post #3





Group: Members
Posts: 3
Joined: 1-February 18
Member No.: 26,582



Thanks for the reply, that has helped.

The "PHP works" did not work.
Changed extension to .php and then got error ....
Parse error: syntax error, unexpected '<' in ......./Index.php on line 73

Found a '?' in place of a '/' (so easy to do and miss :-( )

Changed and now works.

????? So all my pages should be .php extensions if I want PHP includes ?
Any negative implications with that ??
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 3 2018, 07:17 AM
Post #4


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



QUOTE(HenryH @ Feb 3 2018, 10:25 AM) *

????? So all my pages should be .php extensions if I want PHP includes ?
Any negative implications with that ??


Not just for includes, for PHP in general. But they don't have to be, this can be configured on the server (e.g. with a .htaccess directive on Apache). Details vary, so it's perhaps best to ask your web host.

No particular disadvantage with a new site, but on an existing one you'd have to change a lot of existing pages and URLs, add redirects for external links, etc.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
HenryH
post Feb 3 2018, 10:59 AM
Post #5





Group: Members
Posts: 3
Joined: 1-February 18
Member No.: 26,582



OK thanks.
If I start to delve into .htaccess /Apache then I will quickly sink. Already out of my depth a little as only started to think about coding a webpage about 10 days ago.

Rightly or wrongly I gave up with Wordpress pretty quickly as could not adapt the pages to my needs. Realised that I would need HTML/CSS for that too. Steep learning curve epecially with the different languages. I will get there slowly.
Thanks again.
Henry H
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 3 2018, 02:21 PM
Post #6


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



It's usually very simple: just create a textfile called ".htaccess" and add one line of text in it (exactly what may vary, so ask your web host), then upload it to your web root directory. But again, it's not necessary unless you really want it.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th March 2024 - 10:06 PM