
RonnieMac
Members-
Posts
11 -
Joined
-
Last visited
RonnieMac's Achievements

Newbie (1/5)
0
Reputation
-
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
There seems to be plenty of conflicting information about using ETags. Some say use 'em, some say avoid 'em. I'm checking to see if my VPS server has it configured in Apache. Otherwise, sticking with iFrame works perfectly and has no caching problem whatsoever. Thanks again for the help. It is appreciated. This is my first visit to PHP Freaks and the experience has been worthwhile. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
Got it. Been digging around but man is there plenty of conflicting information out there. The common refrain for ETags is "turn 'em off." So, basically, if ETags have been set up on Apache then simply putting it into the directive would make it active on that specific directory. Since each image served has a unique version/query appended would that be sufficient for the browser to detect that the ETag is serving a new file? That's the whole point. To keep the browser from caching the image at any time. You've been very helpful and patient. Much appreciated. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
Thanks Requinix. Alright. Looks good, but to be honest finding something on the interwebs that's related to step-by-step is a challenge, plus lots of folks with pros and cons, disputes over configuration, and even some overhead issues, et al (not that having PHP serve a tagged image isn't overhead). I'm sure they're around, but I haven't been able yet to find options that describe how to turn on ETags easily. Apache is a good source for the geekier minded than me, but I'm digging into it. From what I can see of your directive above I should be able to drop it into the images directory and somewhere set the ETag so it expires after x-seconds, but only for that directive. Is that correct? Do you have a recommended source for more detail? Or, some examples. I'm wading through Google now. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
OK, here's a live sample: Mac360.org In the right sidebar are two images (from an array of 12). The Top Right Sidebar Image uses iFrame but accesses the same images from the same array. The Bottom Right Sidebar Image uses the PHP array from Requinix above, and, indeed appends the version/query string, but I've noticed that the time is not updated quickly. Not sure how that happens in that PHP array. As for htaccess, I've used plenty of directives with much the same results. Works on some browsers, but not on others: <IfModule mod_expires.c> ExpiresActive off </IfModule> <IfModule mod_headers.c> Header unset Cache-Control </IfModule> That one among others, including this (htaccess in the image directory), work sporadically. <IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 2 seconds" ExpiresByType image/png "access plus 2 seconds" </IfModule> Again, the objective is to have the images rotate and not be cached by the browser. In Safari both image change as desired. In Chrome, only the top image (iFrame) will refresh and change, while the bottom image remains the same. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
Agreed. Expires sucks. Just starting muck around with Etags but I see some issues on the horizon where images are stored on a CDN (Amazon) vs. the local server. I'll check it more. If you have a sample of a directive that works across the board I'll be fully thankful and appreciative, but all I've seen (and most of what I've read) indicates consistent inconsistency. Your $time = time has promise. Indeed, it drops in a number string, but I'm still seeing browsers cache the same page so what I'm not sure of is how frequently PHP creates the number appended to the image URL. I'll post a live sample site in a few minutes using the code above as well as an iFrame solution. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
Exactly. And it's important. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
Thanks. Not sure I follow that to a solution. The array contains the link to the image. I'm trying to find a way to get a version/query string appended to the end of the image link. The array handles the rotation of the images, but the version/query string is needed to break the caching problems. Browsers don't agree or obey htaccess directives with any consistency. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
1 - Yes, the right directives are used in .htaccess (there are many; tried them all). Not ALL browsers obey the directives. That's fact. And that's part of the problem. 2 - No, I do not want the images cached. Period. With every page reload I want a new or different image displayed. 3 - Yep. Caching is a problem. I do NOT want the images cached. .htaccess and directives do NOT always work. A version query string does. So, back to the original question; how can a random number be inserted as a version at the end of the images in the array? -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
That's another issue because browsers do not obey the .htaccess headers the same way. Even using .htaccess to set image caching at x-seconds does not always work, particularly in Chrome, but Safari, Firefox, too, and don't get me started on IE. There won't be many images in the rotation but each one needs NOT to be cached, hence the desire to have a version or string appended to the image URL. -
How To Add Random Number Query String Within PHP Array Links?
RonnieMac replied to RonnieMac's topic in PHP Coding Help
Actually, I do not want browsers to cache the images in the array, hence the problem. The problem with a version number is that it doesn't change automatically, so the browser caches it anyway. I've tried a few .htaccess tricks to 'prevent' browser caching, including a '1 seconds' but browsers mostly ignore the header settings. So, what I want is a new 'version number' in the query string with every hit so the images will rotate appropriately but NOT be cached by the browser. That's important in this case. -
The objective is to add a random number to the end of rotating images in a PHP array to prevent browsers from caching the image. The number should be appended to the end of the image URL I have the array, and it works great. I have a random number generator, and that works. I'm doing something wrong when using PHP to apply a random number to the links in the array. Here is the array sample which contains link and image: <?php $content1 = '<a href="http://example.net" title="Example 1" target="_blank"><img src="http://example.com/gallery/image-1.png" alt="Image 1" width="300" height="250" class="gallery-image"></a>'; $content2 = '<a href="http://example.net" title="Example 2" target="_blank"><img src="http://example.com/gallery/image-2.png" alt="Image 2" width="300" height="250" class="gallery-image"></a>'; $content3 = '<a href="http://example.net" title="Example 3" target="_blank"><img src="http://example.com/gallery/image-3.png" alt="Image 3" width="300" height="250" class="gallery-image"></a>'; $content4 = '<a href="http://example.net" title="Example 4" target="_blank"><img src="http://example.com/gallery/image-3.png" alt="Image 4" width="300" height="250" class="gallery-image"></a>'; $content = array($content1, $content2, $content3, $content4,); shuffle($content); ?> <?php print $content[0] ?> This is the random number generator: <?php echo rand() . "\n"; ?> What I want should look like this: $content1 = '<a href="http://example.net" title="Example 1" target="_blank"><img src="http://example.com/gallery/image-1.png?29384756" alt="Image 1" width="300" height="250" class="gallery-image"></a>'; I've attempted to put the random number generator in the array's text string, but I'm doing something wrong, as either it won't generate a number, or the PHP code displays within the HTML, so I'm unsure of how the random number would generate within the array HTML text. Again, the objective is to add a random number query string to the end of the image URL so the array still displays the image and prevents a browser from caching the image when/if a page is refreshed. I'm not sure how or if the random number generator can be placed into the array's text and image URL. Any better way of doing this?