* create web pages with php

Homeless Posts from the old forum system
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

is it possible to insert php before the 'Header' on html pages when creating website ? also can I make files have '.php' extension ?
thanks.

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

create web pages with php

Post by Valkrider »

I haven't used the create webpages functions in FH but my comments relate to standard files.

Any html file can have the php file extension instead of html and it will display fine in a browser.

So you should be able to do what you want. You will probably have to alter any code in the FH generated pages to reflect the new file extension. Alternatively you may be able to do it using redirects in htaccess if you are running the site on a *nix server.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

Thank you for your help.
I was hoping that as i have over 4000 html pages produced i could use FH to produce .php files not .html files and also be able to insert code before the html header. Sadly unless there is some software to do this it seems it cannot be done. I cant face changing every page manually for this number every time i need to upload the site. If anyone else has any ideas i would be very grateful. Thanks
User avatar
Valkrider
Megastar
Posts: 1563
Joined: 04 Jun 2012 19:03
Family Historian: V7
Location: Lincolnshire
Contact:

create web pages with php

Post by Valkrider »

This is something that you could knock a php server side web application to do quite easily.

Don't forget php and html pages are only simple text files so this is something you could do with a macro in MSWord or similar document editing programme. It is something Dreamweaver could do if you have it or by breaking them down in to smaller numbers of files something the free Notepad++ could do.
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

create web pages with php

Post by tatewise »

Could you give some more details of the kind of textual changes you want to make to the HTML files to create the PHP files?

There is an Improve Website or CD DVD HTML Plugin that edits FH website HTML, that you may be able adapt to perform the edits automatically, including changing the file-type from HTML to PHP, and inserting any shared script files.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

Thanks for your response. I did wonder if there was a plugin but not sure how to do any changes.
I want to put a few php lines above the html header to secure the pages. The code would be

CheckLogin())
{
$fgmembersite->RedirectToURL('../login.php');
exit;
}
?>

This is to prevent direct access from the internet to any given file.
Once this code is in each file i would then need to change the file name from html to php. This would involve changing the .html extension in every one of the 4000+ files where there are links to other pages and also its own file extension. I hope this explains it but please let me know if there is anything else needed. I might need help to change a suitable plugin to do the job.
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

create web pages with php

Post by tatewise »

Start by learning about Plugins by looking at the FH Tools > Plugins > More>> > How to Write Plugins and try writing a simple Plugin.

Also look at the FHUG KB under Plugins.

The Improve Website or CD DVD HTML Plugin would be a good starting point, because it identifies the website folder, and reads & writes HTML files to update URL hyperlinks.
So this could be adapted to perform your PHP insertions, alter hyperlinks from HTML to PHP, and rename filetypes.
I am its author so could help if you get stuck.
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

create web pages with php

Post by tatewise »

Does the Creating a website thread offer alternative access protection, that is probably more easily implemented?
In particular the use of a .htaccess file - just Google for more details.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

Thanks for your comments. I think that using a plugin to amend the html files to php and adding php code will be the answer. My only problem is understanding LUA and being able to build a plugin that does this.
I am happy to have a go but my web design brain may not be able to cope with the big difference in code language. I dont know where i will start this and the plugin help/how to has only confused me.
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

Yes you can put php anywhere on an html page - I put quite a bit of code before the tag on my pages.

Another thing to add to your php page right after the <?php would be:
// php compressor
ob_start('ob_gzhandler');

As this can make the pages load faster.
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

create web pages with php

Post by tatewise »

Bonzo ~ I am not very familiar with php, so may I ask two questions that might help ruhane?

(1) You say
You can put php anywhere on an html page.
Does this mean the php can be at the end of the section, just before ?
If so, then the FH Website Wizard - Step 8: Final Details - Advanced option can insert php there.

(2) Do the .html files have to be renamed to .php files?
If not, then the option (1) above is all that is needed.
Problem solved.
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

I have not seen the FH Website Wizard. But putting some php within the header should be OK depending what it does.

On my websites I setup all the page titles, metadate navigation etc. before the tag and the call it within the

Code: Select all

<head>
      <title><?php echo $title; ?></title>
      <myta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8' />
      <myta name='descryption' content='<?php echo $descryption; ?>' />
      <myta name='keywords' content='<?php echo $keywords; ?>' />
      <myta name='robots' content='index, follow' />
      <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />
    <link rel='stylesheet' href='/reset.css' type='text/css' />
      <link rel='stylesheet' href='/style.css' type='text/css' />
</head>
This all works without any problems.

Unless you want to modify the .htaccess file to make html pages work as php pages ( Google .htaccess parse html as php ) they do need the extension changing or else the php will be displayed as text on the page.

I hope this has been of help.
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

Alternatively you may be able to do it using redirects in htaccess if you are running the site on a *nix server.
Valkrider was talking about using .htaccess mod-rewrite
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

I have looked at the website wizard and I would probably put the code ruhane wants into the body BUT depending on his redirect method it might create an error if he is redirecting with a header(). In that case it would be better to display a message instead of an automatic redirect.

This still will not get over the problem of the file extension - perhaps there could be an option of an html file or php file type added by the developers?
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

I have just been thinking about the problem and the code ruhane is using is probably using a session variable to track the user. This means it needs to go at the top of the page even before the .
I have not used cookies but it could probably be done using one of those and in that case the method above could be made to work.

There are file extension changer programs about so that part should be quite easy.

I think I am going daft - why not put the files into a password protected folder and then the files do not need extra code or the extensions changing [rolleyes]
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

create web pages with php

Post by tatewise »

Bonzo said
why not put the files into a password protected folder
Is that what my earlier cross-reference to the Creating a website thread is talking about, regarding the use of a .htaccess file?
User avatar
Valkrider
Megastar
Posts: 1563
Joined: 04 Jun 2012 19:03
Family Historian: V7
Location: Lincolnshire
Contact:

create web pages with php

Post by Valkrider »

I also suggested using htaccess to do the redirect to save renaming the page extension.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

Hi Bonzo and Tatewise
In order to prevent access to pages you can put them in a protected directory. I have done this. However, once you access a page and know its address you can access the page anywhere online without any password being required!
All I want to do is get FH to produce the pages, then I want to change the file extension to .php and all internal links to .php. In order to protect the pages, by inserting the php code (must be at the top of the page before header etc)I put on this thread, you can prevent external access unless you have a password or are already signed in.
I thought a simple plug-in could be used to add the php in the right place (current FH wizard won't do this) and change .html to .php where required. This would ensure the security of the pages online using a log in to the data directory.
Where do I go from here?
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

create web pages with php

Post by tatewise »

I will see if I can adapt the Improve Website or CD DVD HTML Plugin for you.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

Thanks very much for all your help. I would really appreciate it if the plug in could be adapted.
Thanks
User avatar
Valkrider
Megastar
Posts: 1563
Joined: 04 Jun 2012 19:03
Family Historian: V7
Location: Lincolnshire
Contact:

create web pages with php

Post by Valkrider »

Read up on htaccess. It can prevent access to any file or folder without login. It can also redirect your php without changing the file extension.

Still as Mike is going to have a look for you that is the other way BUT if it were me I would just use htaccess for the initial login and that would protect all the html files behind.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

Doesn't .htaccess have problems with servers?
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

I have not had a problem with it but I use Linux type servers.
However, once you access a page and know its address you can access the page anywhere online without any password being required!
That sounds very odd - once you close a browser down you should get logged out and when you go to the address again you will have to login again. Or else what is the point of having it in the first place?
I belive there used to be ( and may still be ) a method of including the username and password in the URL so you did not need to login every time. I thought it was removed as it was a security risk.
avatar
ruhane
Diamond
Posts: 57
Joined: 12 Jun 2005 16:06
Family Historian: V6
Contact:

create web pages with php

Post by ruhane »

re .htaccess
can I use this to enable my many users (400 or so) to have their own usernames and passwords? Looking online it will only let me have one username and password. There does not appear to be any use of database or administration of multiple passwords and users. Am I wrong?
avatar
Bonzo
Diamond
Posts: 79
Joined: 06 Feb 2012 21:47
Family Historian: V5

create web pages with php

Post by Bonzo »

As far as I know you can have as many passwords and users as you like. This is a link to a online password generator and the page has a link to some more information:
http://www.htaccesstools.com/htpasswd-generator/
You have a password file containing all the users with their passwords.

If you were creating the files through cpanel you may have a problem creating that many users.
Locked