Our site (xixax.com) has two image rotation scripts in the header. They have been working fine forever, but they studdenly stopped working right. When viewed on the forum, they get "stuck" on one image. However, the scripts are intact and work fine when viewed separately:
xixax.com/header_words/
xixax.com/header_caps/
Everyone seems to be having the same problem. The pair of images you get stuck with is random.
Could this be related to a hacking attempt? (We have not changed any files ourselves recently.) I haven't found anything obvious. Can someone give me a better idea of where to look in the FTP?
Were the scripts manually added or used within an installed mod?
They were manually added years ago. The person who did that work is no longer an administrator or member, so that's about the extent of my knowledge on how it was done.
It is working just fine. The reason the images are not rotating when you click to another page on your forum is because your browser is caching the images. In other words your browser is downloading the image to your computer and saving so it doesn't have to pull another copy online when you load a webpage that uses it again.
There are a few techniques around it. One is to us meta tags to control the browser cache. Unfortunately this is not a very reliable way as it can sometimes be ignored
header("Pragma-directive: no-cache");
header("Cache-directive: no-cache");
header("Cache-control: no-cache");
header("Pragma: no-cache");
header("Expires: 0");
Another way is adding a random get parameter to the img src URL. It won't affect the php image chooser, but it will make the browser think it is a different image so the browser won't pull from the cached record.
http://custom.simplemachines.org/mods/index.php?mod=2847
Hows this Colin?
Nice find, Mr. Fossil. That would work, but it doesn't look like it allows you to select multiple random header images to be displayed at the same time. If you do use this method, though, it would eliminate the need to even use your PHP rotator script.
Quoteselect multiple random header images
Maybe if the images were made into one using gimp or similar?
Well if it was one image it would have to have a transparent center, or the same color of the theme header background, and span the width of the entire header. That would be quite a large image and would take some unnecessary time to download. I can't say I would recommend that, but it sure is a valid thought.
Interesting. I thought it might be a cache thing, but it suddenly started happening for everyone at exactly the same time. Why on earth would something like this suddenly surface after years of working? Could it possibly be Go Daddy causing a problem? (We switched to them 4 or 5 months ago.)
I located the file where the script is executed... themes/default/index.template.php
I don't see any malicious code, and the script appears to be intact. Here is the script:
<script language="JavaScript"><!--
var now1 = new Date();
if (document.images) {
document.images.myImageName1.src = 'http://xixax.com/header_caps/index.php?' + now1.getTime();
}
//--></script><script language="JavaScript"><!--
var now2 = new Date();
if (document.images) {
document.images.myImageName2.src = 'http://xixax.com/header_words/index.php?' + now2.getTime();
}
//--></script>
<img src="http://xixax.com/images/rightheadtopbot.gif" ALIGN="right" />
<img src="http://xixax.com/header_words/index.php" name="myImageName2" ALIGN="right" />
<img src="http://xixax.com/header_caps/index.php" name="myImageName1" ALIGN="right" />
Aha! Who ever wrote the javascript was smart enough to implement the second method I mentioned, but via the clientside, javascript.
The reason why this is not working is because the javascript is being executed prior to the <img> tags being loaded. If you upload your index.template.php I will fix it and upload the correct version.
Excellent! Here it is...
Is anyone able to help with that script? Any help would be greatly appreciated!
Woops. Sorry. I totally forgot about this. I am making the change now.
Try this
I got this error:
Template Parse Error!
There was a problem loading the /Themes/default/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.
You may want to try to refresh this page or use the default theme.
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../Themes/default/index.template.php on line 666
657: implode('', $buttons), '
658: </ul>
659: </div>';
660: }
661: echo '
662:
663: <script language="JavaScript"><!--
664: var now1 = new Date();
665: if (document.images) {
666: document.images.myImageName1.src = 'http://xixax.com/header_caps/index.php?' + now1.getTime();
667: }
668: //--></script><script language="JavaScript"><!--
669: var now2 = new Date();
670: if (document.images) {
Unescaped single quotes in that javascript are causing the echo statement to prematurely abort.
Woops I didn't catch those nasty little single quotes. Give this one a try
Hmm. Unfortunately that didn't fix the script, and it created a little gap between each image and made text larger. Screenshot attached.
Can anyone help with this?
Someone completely rewrote the rotation script that's in index.template.php, and that fixed it.