PDA

View Full Version : Header Problem?


SYP}{ER
11-24-2002, 12:12 AM
I have a file stored on rbnb.aaron-wright.com which generates itself as a .js file. The JS file has this in it:

document.write ('Random fact here.');

That fact is generated using a random mysql_query and there are no errors in my document. Now I use this to have something document.written onto my site at aaron-wright.com:

<script type="text/javascript" src="http://rbnb.aaron-wright.com/rand.php?params=gohere"></script>

The thing is, it doesn't work. Nothing is written.

That same file is stored on my home computer running PHPDev and if I point to that file instead, it works!

What's going on?

Here's the source:


<?
header("Content-type: text/javascript");

mysql_connect ("****","****","****");
mysql_select_db ("****");
if ($section!="avatars"){
$sql = "SELECT body,source FROM entries WHERE LENGTH(body)<".$maxlength." AND section='$section' ORDER BY RAND() LIMIT 1";
$random_row = mysql_fetch_array (mysql_query ($sql));
$random_row["body"] = str_replace("'","\'",$random_row["body"]);
$random_row["source"] = str_replace("'","\'",$random_row["source"]);
if ($type=="oneliner"){
?>
document.write ('<?=$random_row["body"]?> &mdash; <'+'i><?=$random_row["source"]?></'+'i>');
<?
}else if ($type=="formatted"){
?>
document.write ('<?=$random_row["body"]?><br /><br /><div align="right"> &mdash; <i><?=$random_row["source"]?></i></div>');
<?
}
}
?>


Thanks for any ideas :)

firepages
11-24-2002, 03:09 AM
what sort of errors ? I just get a javascript error when including the script tags, but on readfile() I get this ..

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /<removed>/var/www/html/rand.php on line 8

!

SYP}{ER
11-24-2002, 11:48 AM
That's because the file is referenced with a query string too.

"http://rbnb.aaron-wright.com/rand.php?section=facts&maxlength=1000&type=formatted&randNum=".rand(1,10000000);

That's the src for the script tag. The last random number assures that the file is never cached.

Example:

http://rbnb.aaron-wright.com/rand.php?section=facts&maxlength=1000&type=formatted&randNum=158181

:)