Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP publishing JavaScript
    text
    copied!<p>I have a PHP script that publishes customised JavaScript based on the parameter, with header type as <code>text/javascript</code>. This PHP URL is included in the <code>src</code> of a <code>&lt;script&gt;</code> tag. However, there seem to be an issue, because the script seems to be nonfunctional. As in, I have an alert inside the script, which should be executed immediately after inclusion, but it's not happening. Where am I going wrong?</p> <p><strong>Server Side PHP</strong></p> <pre><code>&lt;?php //Exploding the path after the file widget to get user details $expl = explode("/",$_SERVER['PATH_INFO']); $c=count($expl); //Handling the cases as widget/a widget//a etc switch($c) { case 2: if(empty($expl[0]) &amp;&amp; !(empty($expl[1]))) pumpValid(); else pumpInvalid(); break; case 3: if(empty($expl[2]) &amp;&amp; !(empty($expl[1])) &amp;&amp; empty($expl[0])) pumpValid(); else pumpInvalid(); break; default: pumpInvalid(); break; } function pumpValid() { global $expl; //Checking for a matching account in the urllist include('embedUrl/urllist.php'); if(isset($customerList[$expl[1]])) { header("Content-Type: text/javascript"); //Setting the host path for fetching the JS files later. As in stage or vidteq.com echo "alert('h');"; echo 'var _serverHostUrl="http://'.$_SERVER["SERVER_NAME"].eregi_replace('widget.*','',$_SERVER["REQUEST_URI"]).'";'; } else pumpInvalid(); } function pumpInvalid() { //Should redirect to error/home page echo "Are You Nuts"; } ?&gt; function init() { alert('hi'); addJSinHead('jquery-1.3.2.min.js'); addJSinHead('OpenLayers.js'); addJSinHead('json2.js'); addJSinHead('dom-drag.js'); addJSinHead('globals.js'); } function addJSinHead(fileName) { var head=document.getElementsByTagName('head'); var new=document.createElement('scrpit'); new.src=_serverHostUrl+'/js'+fileName; new.type='text/javascript'; head.appendChild(new); } init(); </code></pre> <p><strong>Inclusion in client side HTML</strong></p> <pre><code>&lt;script src='http://rak/cvs/widget/cis/' type='text/javascript'&gt;&lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload