 |
|
 |
|
Views: 235,713,351 Time: 2013-05-18 04:46:05 AM | 10 users online: Desert-Fox, DonnyKD, Kazeshin, natnew, Pokeymeister80, smkdan, Tahixham, Vinnyboiler, WhiteYoshiEgg, Zero-X - Guests: 26 - Bots: 12 | Users: 22,832 (1,277 active) Latest: Lithuanian Dude |
|
|
 |
|
 |
|
| Tip: The lowest row of 16x16 tiles in a level do not appear. Avoid having a low platform that looks like a bottomless pit. |
|
|
|
 |
|
 |
|
 |
|
 |
|
| Randomization issues with PHP |
|
Forum Index - Hobbies - Computers & Technology - Randomization issues with PHP |
|
Pages: 1  |
|
|
|
| Posted on 2011-12-09 01:16:34 PM |
Link | Quote |
|
I'm working on a randomized layout for December, and I have the random image generator working:

There are two problems, though: The first is that the image only changes when the user refreshes the page; revisiting it or visiting a different page won't change anything (in fact, you can see that with my current layout and the old Tamafluriver avatar). The other related problem is that multiple calls to the PHP file will result in the same image being generated:

I could solve the latter issue, I suppose, if I were to have the PHP return an entire .css file with the images predetermined instead of having the .css file call the PHP for each image, but it would be a lot more of a hassle, and it wouldn't solve the first problem. Does anybody have a solution?
The code, if it helps:
Code<?php
$r = rand(1,100);
if ($r <= 33)
{
$r = rand(1, 4);
header('Location: ' . 'http://media.smwcentral.net/Kipernal/CLLayout/g' . sprintf("%d", $r) . '.png');
}
else if ($r <= 60)
{
$r = rand(1, 5);
header('Location: ' . 'http://media.smwcentral.net/Kipernal/CLLayout/s' . sprintf("%d", $r) . '.png');
}
else if ($r <= 80)
{
header('Location: ' . 'http://media.smwcentral.net/Kipernal/CLLayout/ice.gif');
}
else
{
$r = rand(1, 3);
header('Location: ' . 'http://media.smwcentral.net/Kipernal/CLLayout/a' . sprintf("%d", $r) . '.png');
}
?>
Incidentally, I apologize if that code is sloppy, but my knowledge of PHP is next to nothing.
|
| Last edited on 2011-12-09 01:16:53 PM by Kipernal. |
|
| Posted on 2011-12-09 01:58:45 PM |
Link | Quote |
|
Browsers often cache stuff, to improve performance and save bandwidth on both ends.
I think you can fix half of the problem by using header("Cache-Control: no-cache");, but I don't think you can make it download the same file multiple times on the same page.
|
|
| Posted on 2011-12-09 03:15:35 PM |
Link | Quote |
|
Originally posted by AlcaroBrowsers often cache stuff, to improve performance and save bandwidth on both ends.
I think you can fix half of the problem by using header("Cache-Control: no-cache");, but I don't think you can make it download the same file multiple times on the same page.
That seems to be working nicely; thank you. I suppose I'll just have to make multiple copies of the same file to solve the second problem, then.
|
|
|
Pages: 1  |
|
|
|
|
Forum Index - Hobbies - Computers & Technology - Randomization issues with PHP |
|
|
 |
|
 |
The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.
Copyright © 2005 - 2013 - SMW Central Legal Information - Link To UsTotal queries: 29
|
|
|
|