CodeIgniter Forums

Full Version: having a chat widget appear (or not!)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'd like to offer paying customers premium support. I have a support widget that I plan to use on a system called tawk.to. They advise to embed the following code on the page. 
<!--Start of Tawk.to Script-->

<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->


Now in my case I am adding the a few lines of HTML at the bottom of every page (see below). Can I just paste the above script onto that page and expect it to display? 
<h1>company</h1>

<p></p>
<a href="https://researchstudytoolkit.tawk.help/category/setting-up-the-research-credit-study-toolkit#company-tab" target="_blank">help on setting up the research study online</a>
<br>
<br>

can I just place the above script here?
I managed to get the regular old chat widget working. Now I just need to be able to have that appear only for paying users. I created a flag in the session vars for it.  I then tried adding this code. Can I not wrap javascript within a php section? I need to use php to check if the user gets premium support or not. 

<?php
        if ($_SESSION['premium_support']==1)
          {
          <script type="text/javascript">
              var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
              (function(){
                  var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
                  s1.async=true;
                  s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default';
                  s1.charset='UTF-8';
                  s1.setAttribute('crossorigin','*');
                  s0.parentNode.insertBefore(s1,s0);
              })();
          </script>
          }

?>         

How can I accomplish this? 
<?
?>         
You need to load the script on startup or it will not load later, best bet would to add it to a div then hide it.
After that if they are a paying customer then show the hidden div.
I used pusher.Io realtime service for notifications and chat communication
Pusher. Io has great service and clear documentation , eazy work with it

Pusher. Io offers free and perumin plans too
For what version of CodeIgniter are you searching this solution?
You can accomplish this, but you can't just embed Javascript code directly in your PHP code.

Code:
<?php if ($_SESSION['premium_support']==1): ?>
<script type="text/javascript">
  var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
  (function(){
      var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
      s1.async=true;
      s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default';
      s1.charset='UTF-8';
      s1.setAttribute('crossorigin','*');
      s0.parentNode.insertBefore(s1,s0);
  })();
</script>
<?php endif; ?>

The only thing to make sure of is that the session variable 'premium_support' has a value.