Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Sequential Image Rotation

Posted on 2009-04-13
Medium Priority
Last Modified: 2013-12-25
I need a script that changes images every time the page is refreshed , the images should change is sequence not in random , for I have an image with is cut into two parts on the  right side and one in the middle, when the page is reloaded the images should change in sequence.
Question by:nicklb007
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
LVL 39

Expert Comment

by:Roger Baklund
ID: 24130835
On what plattform will this be running, which scripting language do you want to use?

Author Comment

ID: 24130890
The platform is Linux , any scripting language would work , javascript , php or perl...
LVL 39

Expert Comment

by:Roger Baklund
ID: 24131085
Please explain in more detail what you want to do.
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control


Author Comment

ID: 24131150
I need a script that rotate images  in sequence every time the page loads , the script can be written in any language. for example the following JavaScript script will rotate images in sequence every certain time , I need the rotation to be on page reload not every 5 seconds as in this example

<script type="text/javascript" src="bannerRotator.js"></script>
<script language="javascript">
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {

// Banner 1

var myBanner1 = new BannerRotator();

myBanner1.add('', 'images/banner1.jpg');
myBanner1.add('', 'images/banner2.jpg');
myBanner1.add('', 'images/banner3.jpg');

myBanner1.timer = 5;// 5 secs between images

// Banner 2

var myBanner2 = new BannerRotator();

myBanner2.add('', 'images/banner_side1.jpg');
myBanner2.add('', 'images/banner_side2.jpg');
myBanner2.add('', 'images/banner_side3.jpg');

myBanner2.timer = 5;// 5 secs between images

// Set-up display

  myBanner1.bind('banner1');// match to ID of element.

  myBanner2.bind('banner2');// match to ID of element.
LVL 39

Expert Comment

by:Roger Baklund
ID: 24132073
You have two sets of banners, "Banner1" and "Banner2". In the example there was three of each, was that a coincidence or are the banners related to each other, like pairs?

Do you want to rotate the banners per user or globaly? The difference is, if you rotate globaly, you will show each banner equally many times. If it rotates per user, the first banner will get more views, the second fewer (requires a reload) and the third even fewer, it requires that the user reloads the page twice.

Author Comment

ID: 24132115
The images are related to each other like page for example banner1 and side1 needs to be loaded at the same time , I prefer the rotation to be globally
LVL 39

Expert Comment

by:Roger Baklund
ID: 24132319
ok. Then you need a single global counter. This is done with an integer. You can have a variable starting with value 1, incrementing by 1 for each page load until it is larger than the number of banners, then it resets to 1. Or you can have a counter which goes on for ever, and use a MOD operator to map any number to a banner.

You need to store this counter somewhere, is a mysql database an option?

Author Comment

ID: 24132497
sorry the mysql database is not an option for I don't have access to the control panel, on the other hand I have a script that worked on my test server but did not work on the main server . The script is php
            $max=3;//quantity of images

$fp=fopen ("img.txt", "r");
$n=fread ($fp, filesize ("img.txt"))+1;  
if ($n>$max)
fclose ($fp);

$fp=fopen ("img.txt", "w");
fwrite ($fp, $n);
fclose ($fp);

print '<img src="pic'.$n.'.gif"  height="180" width="446"  border="0" />';

The script created img.txt  on my test server, and the sequence is ok when I moved the script to my main server, img.txt was not created instead the first image is displayed . the server has PHP Version 4.4.1 installed with the following info
Server API       Apache
Virtual Directory Support       disabled
Configuration File (php.ini) Path       /etc/apache/php.ini
PHP API       20020918
PHP Extension       20020429
Zend Extension       20050606
Debug Build       no
Zend Memory Manager       enabled
Thread Safety       disabled
Registered PHP Streams       php, http, ftp, https, ftps, compress.bzip2, compress.zlib

Zend logo This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

PHP Credits
PHP Core
Directive      Local Value      Master Value
allow_call_time_pass_reference      Off      Off
allow_url_fopen      On      On
always_populate_raw_post_data      Off      Off
arg_separator.input      &      &
arg_separator.output      &      &
asp_tags      On      On
auto_append_file      no value      no value
auto_prepend_file      no value      no value
browscap      no value      no value
default_charset      no value      no value
default_mimetype      text/html      text/html
define_syslog_variables      Off      Off
disable_classes      no value      no value
disable_functions      no value      no value
display_errors      Off      Off
display_startup_errors      Off      Off
doc_root      no value      no value
docref_ext      no value      no value
docref_root      no value      no value
enable_dl      On      On
error_append_string      no value      no value
error_log      no value      no value
error_prepend_string      no value      no value
error_reporting      2047      2047
expose_php      On      On
extension_dir      /usr/lib/php/extensions/      /usr/lib/php/extensions/
file_uploads      On      On
gpc_order      GPC      GPC
highlight.bg      #FFFFFF      #FFFFFF
highlight.comment      #FF8000      #FF8000
highlight.default      #0000BB      #0000BB
highlight.html      #000000      #000000
highlight.keyword      #007700      #007700
highlight.string      #DD0000      #DD0000
html_errors      On      On
ignore_repeated_errors      Off      Off
ignore_repeated_source      Off      Off
ignore_user_abort      Off      Off
implicit_flush      Off      Off
include_path      .:/usr/lib/php      .:/usr/lib/php
log_errors      On      On
log_errors_max_len      1024      1024
magic_quotes_gpc      Off      Off
magic_quotes_runtime      Off      Off
magic_quotes_sybase      Off      Off
max_execution_time      30      30
max_input_time      60      60
memory_limit      16M      16M
open_basedir      no value      no value
output_buffering      4096      4096
output_handler      no value      no value
post_max_size      8M      8M
precision      14      14
register_argc_argv      Off      Off
register_globals      Off      Off
report_memleaks      On      On
safe_mode      Off      Off
safe_mode_exec_dir      no value      no value
safe_mode_gid      Off      Off
safe_mode_include_dir      no value      no value
sendmail_from      no value      no value
sendmail_path      /usr/sbin/sendmail -t -i       /usr/sbin/sendmail -t -i
serialize_precision      100      100
short_open_tag      On      On
SMTP      localhost      localhost
smtp_port      25      25
sql.safe_mode      Off      Off
track_errors      Off      Off
unserialize_callback_func      no value      no value
upload_max_filesize      2M      2M
upload_tmp_dir      no value      no value
user_dir      no value      no value
variables_order      GPCS      GPCS
xmlrpc_error_number      0      0
xmlrpc_errors      Off      Off
y2k_compliance      On      On
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24135841
Cookie perhaps?
LVL 39

Expert Comment

by:Roger Baklund
ID: 24136205
Insert error checking:
$max = 3; //quantity of images
$fp = @fopen ("img.txt", "r");
if($fp) {
  $n = fread($fp, filesize("img.txt"))+1;  
  if($n > $max) $n = 1;
} else $n = 1;
$fp = @fopen("img.txt", "w");
if($fp) {
  fwrite($fp, $n);
} else echo '(Could not write banner counter!)';
echo '<img src="pic'.$n.'.gif"  height="180" width="446"  border="0" />';

Open in new window


Author Comment

ID: 24139598
I did insert the error checking and got (Could not write banner counter!), with the first image in sequence displayed .  
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 2000 total points
ID: 24139749
The script is not allowed to create a file, but it might be allowed to modify it. Create a file named "img.txt" containing a single character 0 (zero). Upload it to the server. Then try again.

Accepted Solution

nicklb007 earned 0 total points
ID: 24140079
Thank you the script worked I created the file uploaded to server and changed the permission of img.txt  to 777


Author Comment

ID: 24140301
question answered

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question