简体   繁体   中英

Include a section of HTML or SSI within a PHP Script?

I'm working with making my website compliant with EU cookie directives, and on the homepage, I need help with figuring out how to include a cookie warning message, and a the script that disables Google Analytics.

I have made a set of preference cookies to be set for the website.

My site is made with SSIs: meta header newsletter -- page content -- footer

In my Header SSI, before my content, immediately after my body tag opens, I need to include a small page I made to ask for consent for cookies (/inc/cookies.shtml)

how would I get a php script to insert the contents of cookies.shtml?

somewhat wrong code I made :( :

<?php
if ($_COOKIE["shcpr"] == TRUE)
/* If the user has agreed to accept cookies, just stop this script or whatever */
{die()}
else
/* If the shcpr  cookie value is not TRUE, include the warning box */
{include 'inc/cookies.shtml'}

?>

/inc/cookies.shtml

<div id="cookie-outer"> cookie warning content and form to consent and stuff is here </div>

I'm pretty sure you should be putting semi-colons on the end of your statements:

<?php
   if ($_COOKIE["shcpr"] == TRUE)
   /* If the user has agreed to accept cookies, just stop this script or whatever */
   { die(); }
   else
   /* If the shcpr  cookie value is not TRUE, include the warning box */
   { include('inc/cookies.shtml'); }
?>

It's likely that $_COOKIE["shcpr"] contains the string TRUE .

<?php
if ($_COOKIE["shcpr"] == "TRUE")
/* If the user has agreed to accept cookies, just stop this script or whatever */
{die();}
else
/* If the shcpr  cookie value is not TRUE, include the warning box */
{include 'inc/cookies.shtml';}  
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM