Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- HIding Javascript


usavetele - 10:55 pm on Jul 10, 2005 (gmt 0)


Ack, I can't get this to work:

This is in my header:

<?
session_start();
if(!session_is_registered('allow_script'))
{
session_register('allow_script');
$allow_script = true;
}
?>

This is in my "script.php":

<?
session_start();
if($allow_script)
{
header("Content-type: text/javascript");
?>

var exchRate = 1.20379;
function getUSD(price) {
var USD = price * exchRate;
if (USD.toFixed) { // check whether the browser supports that method
USD = USD.toFixed(2); // (2 is the required number of decimals)
} else {
USD = Math.round(USD*100)/100; // less perfect for older browsers
}
USD = '<b>USD $' + USD + '<\/b>'; // concatenation. escape the slash after the <
document.write(USD); // write the result
}

<?
$allow_script = false;
}
?>

This is what's in the body of my page, where the end result should be (note the "/", is this right or wrong?):

<script language="javascript" src="/script.php"> getUSD('42.99'); </script>

This doesn't work, but the following coding works if I add it below the coding directly above:

<?
session_start();
if($allow_script)
{
header("Content-type: text/javascript");
?>

alert("Woohoo! My javascript Works!");

<?
$allow_script = false;
}
?>

Needless to say, I'm at a loss as to what the problem is. I know next to nothing about Javascript of course.

Any help would be much appreciated!

THANKS!


Thread source:: http://www.webmasterworld.com/php/9105.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com