• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Inserting PHP code into an HTML document.

New Here ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

So I have a website which is coded in HTML formatting. I need to insert some PHP code which is for the cookie consent stuff so I can be compliant with GDPR rules.

Do I need to convert the entire website into PHP from HTML format, or is there a way to insert PHP code into an HTML document without it spewing up loads of errors upon compiling?

Thanks

Views

430

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

  1. Does your webhosting account support PHP?
  2. If yes, is your webhosting account (the server) configured to parse HTML documents and look for and process PHP code? Ask your webhost.
  3. If not, you'll have to rename the page with a .php extension and update any links which point to it.
  4. No need to convert the entire site although for consistency it's often good practice, even for pages with no PHP code in them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

If you do change all pages to a .php extension you may want to consider the impact and set up a redirect, this is assuming you are currently serving your pages with a .html extension (its more the norm these to serve pages without an extension). In this case you'll can use mod_rewrite to redirect all old .html files to their .php equivalent with something like this in htacess file:

RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L, R=301]

This keeps everything tidy and it guards against you losing any benefit of established pages that are generating traffic.

Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

How do I do this on an NGINX box?

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

Something like this:

location ~ /(.*).html$

{ 

rewrite (.*).html$ /$1.php;
}


Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

I think you append 'permanent' for a 301 :

location ~ /(.*).html$

{ 

rewrite (.*).html$ /$1.php permanent;
}

Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

Thank you for your reply, most appreciated. However, coming from a Unix/Linux server, where ,htaccess is the norm, where would I apply the code for NGINX?

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

LATEST

Not so familiar with NGINX myself either - I think if you have root access then it should be added in the conf file, path something like: /etc/nginx/nginx.conf ...

Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

Why is it necessary to use a PHP script?  JavaScript solutions are everywhere.

Nancy O'Shea— Product User, Community Expert & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines