Solved

Sequential Image Rotation

Posted on 2009-04-13
14
320 Views
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.
0
Comment
Question by:nicklb007
  • 7
  • 6
14 Comments
 
LVL 39

Expert Comment

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

Author Comment

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

Expert Comment

by:Roger Baklund
ID: 24131085
Please explain in more detail what you want to do.
0
 

Author Comment

by:nicklb007
ID: 24131150
Dear,
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) {
        oldonload();
      }
      func();
    }
  }
}

// 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

addLoadEvent(function(){
  myBanner1.bind('banner1');// match to ID of element.
  myBanner1.startTimer();

  myBanner2.bind('banner2');// match to ID of element.
  myBanner2.startTimer();
});
</script>
0
 
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.
0
 

Author Comment

by:nicklb007
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
0
 
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?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:nicklb007
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
<?php
            $max=3;//quantity of images

$fp=fopen ("img.txt", "r");
$n=fread ($fp, filesize ("img.txt"))+1;  
if ($n>$max)
$n=1;
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
Configuration
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
0
 
LVL 75

Expert Comment

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

Expert Comment

by:Roger Baklund
ID: 24136205
Insert error checking:
<?php

$max = 3; //quantity of images

$fp = @fopen ("img.txt", "r");

if($fp) {

  $n = fread($fp, filesize("img.txt"))+1;  

  if($n > $max) $n = 1;

  fclose($fp);

} else $n = 1;

$fp = @fopen("img.txt", "w");

if($fp) {

  fwrite($fp, $n);

  fclose($fp);

} else echo '(Could not write banner counter!)';
 

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

?>

Open in new window

0
 

Author Comment

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

Assisted Solution

by:Roger Baklund
Roger Baklund earned 500 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.
0
 

Accepted Solution

by:
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

0
 

Author Comment

by:nicklb007
ID: 24140301
question answered
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now