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

Inserting PHP code into an HTML document.

New Here ,
Oct 25, 2018 Oct 25, 2018

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

608
Translate
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
  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.
Translate
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

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 OnRewriteRule ^(.*)\.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
Translate
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

How do I do this on an NGINX box?

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
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

Something like this:

location ~ /(.*).html$

{ 

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

Paul-M - Community Expert
Translate
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

I think you append 'permanent' for a 301 :

location ~ /(.*).html$

{ 

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

Paul-M - Community Expert
Translate
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

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 is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
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
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
Translate
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

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

Nancy O'Shea— Product User, Community Expert & Moderator
Translate
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