Continue to work on getting my website updated. It is fun learning new things as I work on the site. Ive added rotating images to my pages as well as the background using the rotate.php script from Dan P. Benjamin, Automatic, Ltd. The script is very simple to implement copy the file into the directory with your images then call it from your page or from the css file to rotate the background. Dan P. Benjamin, Automatic, Ltd. random image rotator.
Sample entry for css file:
background: url(images/random-images/rotate.php);
Sample entry for webpage:
<p align=”center”><img src=”images/photography/rotate.php” alt=”random photos” width=”375″ height=”315″ /></p>
To provide a random id for the images I set a variable using uniqid then generate a random number. Then add an id to the rotate.php.
Sample Variable for uniq id: /*<?php $ranzyz345 = md5( uniqid (rand(), 1) ); ?>*/
Sample adding uniq id to rotate.php: /*<img src=”images/directory/rotate.php?id=<?php echo($ranzyz345); ?>” title=”” alt=”Random Marine Corps Emblems and Cheverons” width=”125″ height=”125″ style=”float:left; padding-right: 10px; padding-left: 10px;” border=”1.0″/>*/
For rotating videos or other content randomly I use another php script that read a directory an randomly pulls files from the directory would love to give credit where this file came from but I can”t find it. But here is the code, the only change is enter the path to your directory. I setup a div then use a include to load the file into the page.
Code for random.php /* error_reporting (E_ALL | E_STRICT); $files = array(); $path = “(path to directory)/”; if( $handle = opendir( $path ) ) { while (false !== ($file = readdir($handle))) { if( $file != “.” && $file != “..” && !is_dir( $path.$file ) ) { $files[] = $path.$file; }*/
You need to populate the $files variable before you count it; /*$file = $files[ rand( 0, count( $files ) -1 ) ];*/
Now we can include it! /*include (“$file”); } else { print “no files found”}*/
I wanted to follow up and let you know how , a great deal I loved discovering your web blog today. I would consider it an honor to do things at my office and be able to make use of the tips shared on your web site and also take part in visitors’ remarks like this. Should a position connected with guest writer become offered at your end, make sure you let me know.
I would like to thank you for the efforts you’ve put in writing this website. I am hoping to check out the same high-grade content from you in the future as well. In fact, your creative writing abilities has encouraged me to get my own, personal blog now
I love this.
I’ve found that (at least) FireFox caches stelesheyts forever unless a page is specifically refreshed. Thus, changed stelesheyts under a fixed name won’t be reloaded. My workaround when changing stelesheyts is to give each a different name (i.e. style001.css, style002.css, ) and set a variable in my config.php file for the most current style sheet. I could see doing this php trick when different browsers need different styles. But you could as easily use different style sheets for different browsers and actively set the variable in config.php accordingly. Do that for the part that MUST be different, and use a single common stylesheet for the rest that doesn’t matter which browser is used.
Thanks for that awesome posting. Useful, and it saved MUCH time! 🙂
would it be possible to apply AddHandler to only sieicfpc files and/or directories? forcing to process all css files around all website (lets say in wordpress installation with multiple plugins) would force you to add the header declaration to all these files around and that would be tiring to say least
Or you could simply make a .php file with the heeadr code, and include it in your html as a style-sheet. The browser care about content-type, not file extensions.Thereby you still have the option of using a static .css file when no php is needed in your style sheets, for better performance./henrik
Happen to be trying to find this and learned much more than anticipated in this article. Thanks.
I’m shocked that I found this info so easily.
Heard of something like this for the first time. thanks for sharing it.
I also agree that it is not good to be loading PHP for every style sheet. If you load one PHP page with two dynimac’ style sheets, that’s 3 PHP calls for every loaded page, for every visitor. That will add up real quick if/when your website starts to pull traffic.The best thing to do is leave the stylesheets static. If you need to add dynimac style information, include it in the actual web page in style tags.cigraphics is on the right track for re-generating static style sheets when changes are made to the website, but then you have to worry about browsers caching their CSS sheets because they are expected to be static. I know there are workarounds for that, but why worry about it? Just include any dynimac content in the main web page.
This really solved my problem, thank you!
Thanks
This is good information, I found it through google, and was able add rotating images to my website.
In fact there is only one thing you have to do, i always skip step 1 and name my styhesleets that require processingmystyle.php and in the beginning i use your header(’Content-type: text/css’); to convince server and browser that the file is really css.You can then use for example link rel= stylesheet href= mystyle.php The browser is not interested in the fileextension, only the server uses them sometimes. And i can see what is php, there is no need to work with .htaccess and its also a bit more serverfriendly because most css files get delivered directly. Matthias
That is going to stress the sveerr the easy way is this:function css() {$bg = “red”;$color = “green”;$txt = “Arial”;$css = <<<EOFbody {background-color: $bg; font: $color $txt;}EOF;return $css;}$x = css();file_put_contents('style.css', $x);Add it to your administration panel and when you change the values it will rewrite the style.css file and that's it. You won't need to call it every time you enter the site. And if you want to change the styles you can make more files like style_blue.css, style_red.css etc
There are lots of bad posts around internet, so it’s very good that I found your website which is so good.
This blog rocks.
.
tnx for info!!