1

My server is set to parse HTML documents as PHP and it works fine. However, with this particular code it seems to be not working.

<div class="container">
<div class="pb-4">

<?php
$referrer = $_SERVER['HTTP_REFERER'];
$my_domain = "example.com";
$search_engines = "google|yahoo|bing|altavista|digg";
$pattern = "((http(s)?:\/\/)(\w+?\.)?(?!{$my_domain})({$search_engines}))";
if (preg_match("/{$pattern}/i", $referrer) != false) {
    echo <<<END
    <script type="text/javascript"><!--
    google_ad_client = "xx-xx-xxxxxxxxxxxxxxxxxx";
    /* xxxxxxxx xxxxxx xxx xxx xxx xx xxxxxx */
    google_ad_slot = "xxxxxxxxxxxxxx";
    google_ad_width = xxx;
    google_ad_height = xxx;
    //-->
    </script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
END;
} else {

}
?>

</div>
</div>

When I insert that PHP part and open the page it just displays the END; } else { } ?> on front-end. Any help you can provide with this would be greatly appreciated.

Gihan
  • 1,836
  • 2
  • 7
  • 28
  • 2
    [I can't reproduce](http://sandbox.onlinephpfunctions.com/code/2cde66ab1d4be64216f1d1a4cbf262b39a168283) Is the indentation correct about `END;` ? – Cid Dec 24 '20 at 13:24
  • Yes, happens only when I include it in the HTML. – Gihan Dec 24 '20 at 13:28
  • 1
    What is the extension of your filename? If it is `filename.html` make it `filename.php` then it should work. – Aftab Ansari Dec 24 '20 at 13:42
  • @AftabAnsari If `server is set to parse HTML documents as PHP` then that is not needed. The handler has been modified already. – user3783243 Dec 24 '20 at 13:56
  • 1
    @user3783243 Then there may be mistake in parsing I guess. Because when I executed this code with `.php` extension it is working correctly. – Aftab Ansari Dec 24 '20 at 14:01

0 Answers0