Allow Cookies js causing a php error

2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 12, 2016   (RSS)

By JeffC - January 12, 2016 - edited: January 12, 2016

I am using some js to enable the website visitor to accept our cookie policy.

I am also using the instant website plugin.

Here is my index.php code (calls a page style (one of 6 page templates that contain the rest of the html/php), and then loads the cookie php : 

<?php require_once "website_init.php"; ?>
<?php  if ($page['style']) {
     $stylesRecord = mysql_get('styles', $page['style']);
     if ($stylesRecord['path']) { include($stylesRecord['path']); }
  }
?>

<?php if (!isset($_COOKIE[$cookie_name])): /* Only load if cookie isn't already set */ ?>
<div class="alert alert-warning text-center cookie">
We use cookies to give you the best website experience. By using our website you agree to our use of cookies.
<a href="/cookie-policy.php" class="alert-link">Find out more</a> or
<a href="?allow-cookies=1" id="accept-cookies" class="alert-link">close this alert</a>.
</div>
<script src="/common/js/cookies/cookiealert.min.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function() {
cookieAlert({
element: 'cookie-alert-container',
name: '<?= $cookie_name ?>',
close: 'accept-cookies'
});
}
</script>
<?php endif; ?>

The cookie works perfectly with every page on the website EXCEPT the first page of the website. The error I receive is:

Undefined index: style
/home/xxx/xxx/xx.co.uk/index.php (line 2)
http://xxx.co.uk/?allow-cookies=1

Can anyone explain why the style is undefined on the first page but works on all of the others?

(I am confident that the 'allow cookies js' is functioning on all pages - so a possible solution would just be to suppress the error) 

Thanks

Jeff

EDIT: The error is appearing AFTER the cookies have been accepted.

(my part diagnosis is that by clicking 'close this alert' results in the page load bypassing the styles selection part, but I am baffled as to why it bypasses on the first page but not all of the others)

Jeff