I have a search file – dir/search.php
In search.php:
<script type="text/javascript" src="timeout.js"></script>
In timeout.js:
<script src="functions.php"></script>
In functions.php in one line I have:
document.write('<?php if (!isset($_GET["r"])) { echo "error"; } elseif ($_GET["r"] == "top") { ?><title>Top Results</title><?php } ?>');
I was wondering why when I looked at search.php?r=top, it would display “error”?
While you can do crazy stuff like src’ing PHP files in script tags, the file you source has to be a PHP file which outputs javascript.
In this case, functions.php is actually javascript that outputs PHP. This will never run as it’s expecting PHP.