Inserting a block of JavaScript code into a PHP script -
a friend of mine wanted me gather statistics website gave him following code insert in page footers:
<div> <script> var wandtopsitesuserid; match = document.cookie.match(new regexp("wandtopwildlifesites" + '=([^;]+)')); if (match) wandtopsitesuserid = match[1]; else { wandtopsitesuserid = (+new date * math.random()).tostring(36).slice(2, 12); document.cookie = 'wandtopwildlifesites=' + wandtopsitesuserid + '; expires=tue, 1 jan 2030 00:00:00 utc; path=/'; } document.write('<div style="visibility: hidden;"><a href="http://www.www.fxxxxx.com/"><img src="http://xxxxxx.azurewebsites.net/log/logvisit/?siteid=2&userid=' + wandtopsitesuserid + '&pagename=' + location.pathname + '" alt="wand top wildlife sites" /></a></div>'); </script> </div>
what didn't know he's using php , know absolutely nothing php. when attempts insert code php script, gets following error:
string(125) "smarty error: [in globalcontent:footer line 9]: [plugin] unknown tag - 'wandtopsitesuserid' (core.load_plugins.php, line 198)" string(137) "smarty error: [in globalcontent:footer line 9]: syntax error: unrecognized tag 'wandtopsitesuserid' (smarty_compiler.class.php, line 590)"
not knowing php, have idea how fix this.
he uses samrty template engine requires escape javascript encapsulating within {literal}...{/literal}
:
<div> {literal} <script> var wandtopsitesuserid; match = document.cookie.match(new regexp("wandtopwildlifesites" + '=([^;]+)')); if (match) wandtopsitesuserid = match[1]; else { wandtopsitesuserid = (+new date * math.random()).tostring(36).slice(2, 12); document.cookie = 'wandtopwildlifesites=' + wandtopsitesuserid + '; expires=tue, 1 jan 2030 00:00:00 utc; path=/'; } document.write('<div style="visibility: hidden;"><a href="http://www.www.fxxxxx.com/"><img src="http://xxxxxx.azurewebsites.net/log/logvisit/?siteid=2&userid=' + wandtopsitesuserid + '&pagename=' + location.pathname + '" alt="wand top wildlife sites" /></a></div>'); </script> {/literal} </div>
Comments
Post a Comment