I am looking for a script that can replace the standard image on a page into one selected on an other (please see the code below).
The first page (CHANGE IMAGE) is a page with three images a person can  select. This can be done by checking the radio button in front of one of the  images. If a person clicks the "Change" button, the standard image on the  "PAGE WITH IMAGE" page should be replaced with the selected image.


<FORM METHOD="post" ACTION="/cgi/change">

<INPUT TYPE="radio" NAME="change" VALUE="image2"><IMG SRC="image2.gif">

<INPUT TYPE="radio" NAME="change" VALUE="image3"><IMG SRC="image3.gif">

<INPUT TYPE="radio" NAME="change" VALUE="image4"><IMG SRC="image4.gif">

<INPUT TYPE="button" VALUE="Change">






Text, text, text.<P>



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


1.) will people always go to the first page before arriving at page 2?
2.) what should happen if somebody bookmarks page 2 and returns there?

It is quite easy to change the image on page 2 based on the selection on page 1, however the two questions above are important for a solid solution.

gardensAuthor Commented:
Hi Tobias,

1) This depends. Some will first visit the first page, others will want to change the image immediately.
But if it is easier to create it so that people will not see the page first, this is fine.

2) Page one is a simple page wizard, that allows a person to have his version of the page. So each person will have a separate page (a real page or created on-the-fly this doesn't matter).

Therefore if anyone visits the page after it has changed, the new image is what he sees.

Thanks in advance
Hmmm - this makes it a bit more complicated :-)

Do your users accept cookies?

Here is what I think of:
* When somebody goes to the first page and selects an image we send out a cookie which describes what image has been selected.
* On the second page we check the cookie and if found select the image which is identified by the cookie.
* If no cookie is found a "default" image is chosen.

Does this sound like a solution?

If yes, then you'll get two scripts: one which accepts the formdata from the first page and sets the cookie and a second one which selects the image based on the cookie.

Let me know, if this is a suitable solution and I'll send the code.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

gardensAuthor Commented:
It sounds good, but if someone else visits the person's page he will never have a cookie. Therefore he will always see the "default" image.
The code of the page should actually change.

I realize that this is probably more difficult, so I will add 100 points and give you an "A" if you are willing to create it.
Just to clarify: Page2 is unique per user? Is it sitting in a private directory which is associated with this user?

Means: user1 has the following URLs


and user2


or is it like this:


I need to know this, because at some point the image needs to be replaced and if page2 is the same for all users then we need to store information about the selected image somewhere else.
If every users has his own page2 then we can actually make the change in place by modifying the HTML code.

Sorry for the constant back and forth. Do you happen to have a sample I can look at?


gardensAuthor Commented:
Sorry, I went off-line (family emergency).

Your second description is correct. There is one page wizard for all users. Every user has it's own page two. So:


The HTML code in my first question is what I have at the moment. I am still working on the rather complicated text. However, the layout of the page will stay the same.

sorry for the delay, but I had to put out some fires here at work :-)

I think I understood the scope of the work now and here is what I would suggest to do.

1.) Generate the generic select image page.
2.) when cgi/change is called we need to make sure we know exactly who is calling it (username). I really don't know how you want to do this (login? let the user supply username/password in the form?)
3.) The script below assumes that the cgi-parameter 'user' identifies the username and 'image' selects an image from a pool of images.
4.) The script opens the user-specific html page and search for markers in the page. If these markers are found the image between the markers is replaced by the one chosen.

Let me know, if you need more information


use strict;
use CGI;

# what is the filename of the "second page"?
use constant USER_SPECIFIC_PAGE=>"user-specific-page.html";
# where are all the images?
use constant IMAGES_DIR=>"/www/images";

my $cgi=new CGI;

sub errorOut {
  print $cgi->header();
  print $cgi->start_html("Error");
  print qq{Reason: $reason<br>\n};
  print $cgi->end_html();
  exit (1);

sub userDirFromUserName {

   # given a username compute the user's directory (where the user-specific-page is located)

   return qq{/www/users/$username};

sub mapImage {
   my($selection) = shift;

   #based on the selection made on the first page, select an image and return it's filename.

   my (@images) = ("image1.gif", "image2.jpeg", "image3.gif");

   return $images[$selection];

my $username=$cgi->param('user') || errorOut(qq{'user' parameter missing});
my $userfile=userDirFromUserName ($username)."/".USER_SPECIFIC_PAGE;
my $image=IMAGES_DIR."/".mapImage($cgi->param('image'));
my ($html);

open(HTML,"<$userfile") || errorOut(qq{can't open $userfile - $!});
{ local($/)=undef;
$html=~s{(<!--begin_img-->).*(<!--end_img-->)}{$1<img src="$image">$2}g;
open(HTML,">$userfile") || errorOut(qq{can't update $userfile - $!});
print HTML $html;

print $cgi->header();
print $cgi->start_html("Success");
print qq{Updated: $username uses now image $image<br>\n};
print $cgi->end_html();


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gardensAuthor Commented:
Thanks Tobias for all your hard work. My users will
login on an other page (the members index). A  friend of mine can make the small alteration so that the script will know which member is calling.

Have increased the point (well worth it :) and give you a deserved "A".

Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.