* Create website files with .php extension

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Create website files with .php extension

Post by ruhane » 08 Oct 2015 12:01

I have recently designed a picture gallery using php which will enable files to be displayed online for my database of family tree individuals. This requires the php code to be put in the 4 boxes at the end of the "create a website" feature. This code has been tested off-line and works perfectly, and when online also has no problems. However, i use 1&1 webspace as my web host and their directory protection system which creates a .htaccess file for each of the 5 trees that i have on my website. Using php within .html files can cause problems online so to overcome this the following line of code has to be added to each .htaccess file:

AddHandler x-mapp-php5 .html .htm

Unfortunately whenever the .htaccess files are amended (by 1&1, adding a new user or amending existing user) any manual additions such as the above line are over written. This means that every time this happens i have to edit 5 separate .htaccess files to correct the code. I have spoken with 1&1 and they do not seem able to include this line when they generate the new .htaccess file.

This means that the only sensible solution appears to be to generate website files which have .php not .html extensions. I have tried to build a plugin to do this but got completely lost. Is it possible to enlist the help of someone who knows LUA so that i can create .php files with the added code for the gallery? I would be grateful as the website constantly does not work properly and updating it is becoming a real hassle.
Thank you
Keir

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 08 Oct 2015 12:45

Hi Keir.
I presume you are NOT talking about changing all the FH created web page files from .htm to .php files.

If you can add some ATTACHMENTS that are representative of the files you need, then it will be easier to give some advice.
The Upload attachment tab might not accept .php files, so use .txt files instead.
Alternatively, post web address links to allow us to see the files you want created.

Did you find the plugins:index|> Family Historian Plugins Developer Guide with its plugins:code_snippets:index|> Code Snippets section that includes plugins:code_snippets:save_string_to_file|> Save String To File (code snippet) needed to create text files?
You also need to use the fhGetContextInfo("CI_PROJECT_PUBLIC_FOLDER") API function to get the full Public folder path as the root of the FH web pages folder and .php filenames.

A totally different technique is to create a sub-folder within the FH created web pages folder, in which to hold your manually created .php or .htaccess files, that can be copied up into the FH folder after rebuilding the web pages. Although FH empties its folder, it does not touch sub-folders.

On the other hand, if you are talking about auto-editing all the FH web page files, so that they are all .php, then not only must the filenames be changed, but also every hyperlink within the files must be changed, and detecting them all is not easy. I know as I have done it for my Improve Website or CD DVD HTML Plugin.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 08 Oct 2015 13:09

Mike
Sadly I think that all the files will need to have the .php extension, as the online webspace will only execute the php in htm/html files if it knows that the files are .php or the .htaccess file tells it to manage the files as such. If only 1&1 could amend their code to auto generate the AddHandler line in their .htaccess updates there would be no need to consider this. I don't seem to be able to convince them that this is the simplest and best option. I don't see that it would cause them any problem as the line of code will only operate if you have htm/html files with php code inside them.
Keir

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 08 Oct 2015 13:53

Keir,
Does the php code actually have to exist within the html files?
Can the html files link to external php files, in the same way that they link to external css and js files?
Would that circumvent the problem?

I am no expert in php, so I presume you know for certain that hyperlinks work in the same way.
i.e.
If <a href="fam11.html"> links to file fam11.html
then <a href="fam11.php"> links to file fam11.php in the same way.

You also have to consider all possible html files & links created by FH such as:
index.html
_nameindex.html
_statistics.html
toc2.html
toc4.html

etc...
Plus those created by my Improve Website or CD DVD HTML and Map Life Facts Plugins.

Also do CSS links and script work in the same way within php files?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 08 Oct 2015 14:19

Mike
Thanks for that, I know that the way we have written the php means that it has to be inside the html file, because it uses the id, first name and last name to identify which folder of media to put in the gallery. As a result I will look at ways of changing the code or seeing if I can get 1&1 to put the line permanently in the code structure of the .htaccess file. I will let you know what happens.
Keir

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 08 Oct 2015 15:47

I am not sure if it helps, but to uniquely identify an Individual only needs the Record Id and for ind123.html files the numeric part (123) = Record Id. So if your media folder just uses the Record Id, or perhaps the .html filename, then maybe the php does not need to reside within the .html files?

Perhaps you could read the .htaccess file using plugins:code_snippets:read_direct_from_web_page|> Read Direct From Web Page (code snippet) and edit its text with a Plugin, leaving the results in a PC file to upload to 1&1.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 09 Oct 2015 08:06

Thanks Mike - I obviously need to experiment a bit - I will get back when I have some results!

User avatar
Valkrider
Megastar
Posts: 1534
Joined: 04 Jun 2012 19:03
Family Historian: V7
Location: Lincolnshire
Contact:

Re: Create website files with .php extension

Post by Valkrider » 09 Oct 2015 09:05

Use a bulk rename utility to change all the .html file extensions to .php.

The webserver will happily serve a page with only html code in it as a php page. You will obviously need to delete all the files with the html extension from the webserver as index.html will be served before index.php.

The only problem with this approach is all links in your website that are looking for a .html file will break. You would therefore need to do a search and replace in all your files to change html to php as well. Very messy imho but it would get you what you want.

A better approach may be to move to a conventional host that doesn't limit you in the way that 1and1 do. I moved from them years ago because of this and some other issues with them.

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 09 Oct 2015 10:03

One snag with that Colin, is that not all occurrences of .html in the files are necessarily links to the renamed FH files.
e.g.
Wizard Step 4 - Add Items for Table of Contents offers Link to website that may have URL using .html.
If Source or Repository or other records have links to external website pages then they may have URL using .html, especially after using my Improve Website or CD DVD HTML Plugin.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 20 Oct 2015 14:49

Mike
Good news, i have found a way of converting the published html files to php including all the links and it seems to work fine. This avoids any need to amend the .htaccess file even when it is updated by the host. If anyone wants the details it is a very simple and straight forward process for which i can give a step by step guide.
Keir
ps Thanks for all your help.

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 20 Oct 2015 19:09

Yes, please provide the details, then I can update the FHUG Knowledge Base for creating web sites.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 26 Oct 2015 19:11

Mike, I will prepare a step-by-step guide and let you have it. Do you want me to post it here or send it to you direct?
Keir

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 26 Oct 2015 23:39

Post it here, perhaps in an Attachment.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 27 Oct 2015 16:30

Mike
Here is the file, hope it is clear, if there is anything that needs changing please let me know.
Attachments
Convert html to php.doc
Instructions to convert .html files to .php
(14.5 KiB) Downloaded 215 times

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 27 Oct 2015 21:26

A snag with that is not all occurrences of .html in the files are necessarily links to the renamed FH .php files.
e.g.
Wizard Step 4 - Add Items for Table of Contents offers Link to website that may have URL using .html.
If Source or Repository or other records have links to external website pages then they may have URL using .html, especially after using my Improve Website or CD DVD HTML Plugin.

So replacing those .html with .php would break those links.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

Re: Create website files with .php extension

Post by ruhane » 30 Oct 2015 13:02

Mike, I accept what you say but this is why I either don't put a lengthy url in repository details or I don't put one at all. I find that putting links in all these detail areas means that if you use them and they don't work you tend to shorten the link to just the website address anyway. This obviates the need to worry about those links when you run a bulk rename from .html to .php
I have found that keeping links simple or putting them in notes is far more effective for me. The bulk search and replace followed by renaming the files from .html to .php not only works but has now enabled me to provide an individual gallery of media files (.jpg, .gif, .txt, .pdf etc) which means that I am no longer restricted to what FH is limited to.
I find these galleries enable all my files to be displayed and with a simple click they can be enlarged (twice). I was thinking of offering this gallery solution to FH users - I have yet to completely clean up the code but I have it running on 5 sites online, without any problems so far.
I think that for me personally including links in repositories and submitters etc is 'overkill' so if anyone wants more details about the gallery or conversion of files to .php I am happy to answer any questions.
But thank you again for your help and advice which is always welcome.
Keir

User avatar
ColeValleyGirl
Megastar
Posts: 4853
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Create website files with .php extension

Post by ColeValleyGirl » 30 Oct 2015 14:35

Keir,

The gallery solution sounds interesting -- I'd love to explore it further.

Helen

User avatar
tatewise
Megastar
Posts: 27082
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Create website files with .php extension

Post by tatewise » 30 Oct 2015 15:53

Keir, the point is that the rename & replace technique obviously works for you, but if added to the Knowledge Base must consider all users, so should either be foolproof (which it is not), or have necessary caveats clearly shown (which we now understand).

I might be able to add the technique to my Improve Website or CD DVD HTML Plugin, which knows the difference between FH webpage links and other links, so would only replace the appropriate FH webpage .html extensions.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply