Highlighted

Inserting PHP code into an HTML document.

New Here ,
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

269

Likes

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

Inserting PHP code into an HTML document.

New Here ,
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

270

Likes

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
Oct 25, 2018 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Oct 25, 2018 1
Adobe Community Professional ,
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, ACP - www.webspectrum.co.uk

Likes

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
Reply
Loading...
Oct 25, 2018 1
Adobe Community Professional ,
Oct 25, 2018

Copy link to clipboard

Copied

How do I do this on an NGINX box?


Ben

Likes

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
Reply
Loading...
Oct 25, 2018 0
Adobe Community Professional ,
Oct 25, 2018

Copy link to clipboard

Copied

Something like this:

location ~ /(.*).html$

{ 

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



Paul-M, ACP - www.webspectrum.co.uk

Likes

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
Reply
Loading...
Oct 25, 2018 0
Adobe Community Professional ,
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, ACP - www.webspectrum.co.uk

Likes

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
Reply
Loading...
Oct 25, 2018 0
Adobe Community Professional ,
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?


Ben

Likes

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
Reply
Loading...
Oct 25, 2018 1
Paul-M LATEST
Adobe Community Professional ,
Oct 26, 2018

Copy link to clipboard

Copied

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, ACP - www.webspectrum.co.uk

Likes

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
Reply
Loading...
Oct 26, 2018 1
Adobe Community Professional ,
Oct 26, 2018

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Oct 26, 2018 1