tanc02
asked on
it is very bother me !
I have a random display image, written by perl.
It used html img tag to call the script like:
<img src="http://imsp.stcloudstate.edu:8002/cgi-bin/img.pl">
If I used IE , the images will be displayed just fine, each time I hit reload, I saw different images. That is what I want.
B U T ,
if I used Netscape, no matter I hit reload how many time, it just displayed the first image that is picked to display.
Why the images will not be chnaged. ?
How to solve this problem ?
I must use img tag , and I hate to use SSI.
Because I want to make it as inline image.
Here is my script :
#!/usr/bin/perl
$basedir = "http://imps.stcloudstate.edu:8002/";
@files = ("bup1.gif","bup2.gif","bu p3.gif","b up4.gif"," bup5.gif") ;
srand(time);
$num = int(rand(5));
print "Location: $basedir$files[$num]\n\n";
If I didn't use Location, I will get broken image.
For your imformation, this script is residing at ../cgi-bin/
and the images and img.html is residing at ../../web-docs/
It used html img tag to call the script like:
<img src="http://imsp.stcloudstate.edu:8002/cgi-bin/img.pl">
If I used IE , the images will be displayed just fine, each time I hit reload, I saw different images. That is what I want.
B U T ,
if I used Netscape, no matter I hit reload how many time, it just displayed the first image that is picked to display.
Why the images will not be chnaged. ?
How to solve this problem ?
I must use img tag , and I hate to use SSI.
Because I want to make it as inline image.
Here is my script :
#!/usr/bin/perl
$basedir = "http://imps.stcloudstate.edu:8002/";
@files = ("bup1.gif","bup2.gif","bu
srand(time);
$num = int(rand(5));
print "Location: $basedir$files[$num]\n\n";
If I didn't use Location, I will get broken image.
For your imformation, this script is residing at ../cgi-bin/
and the images and img.html is residing at ../../web-docs/
your are re-loading the same image from the cache!
ASKER
but why IE will display the random images, is that a different between
IE and Netscape ?
How to solve this problem ?
It must be called from img tag
-no SSI, please
IE and Netscape ?
How to solve this problem ?
It must be called from img tag
-no SSI, please
Yes, you are reloading the image from the cache in Netscape. I suggest you change your CGI call to:
<!--#exec cgi="cgi-bin/img.pl" -->
And then change the print statement in your CGI to the following which will get around the problem:
print "<img src=\"$basedir$files[$num] \"> ";
<!--#exec cgi="cgi-bin/img.pl" -->
And then change the print statement in your CGI to the following which will get around the problem:
print "<img src=\"$basedir$files[$num]
ASKER
if I used this <!--#exec cgi="cgi-bin/img.pl" --> , then I have to change
index.html to index.shtml, right ?
But I really hate to use SSI, What if , I want my friend to call this script
from his account and he doesn't have permission to use SSI.
I think there must be a way to solve this problem without SSI.
For example, I saw some web site provide free counter by placing
image tag in my html file, why they can do and I have the problem ?
index.html to index.shtml, right ?
But I really hate to use SSI, What if , I want my friend to call this script
from his account and he doesn't have permission to use SSI.
I think there must be a way to solve this problem without SSI.
For example, I saw some web site provide free counter by placing
image tag in my html file, why they can do and I have the problem ?
ASKER
sorry to reject your answer, because I think there is a way to solve this....
I've done exactly what you want with a very simple JavaScript before, maybe you can use it (or modify it and use a combination of JS and your Perl). Here's the JS and HTML that will work for you. It can also be added to your friends document as well (I tested it from MY server and got a different blue button to reload off YOUR server everytime :)
It works by adding a different search string value after the image href causing the script to reload the image from the server each time...
<SCRIPT LANGUAGE="JavaScript"><!--
function loadImage() {
filenum = Math.round(Math.random() * 4) +1;
var now = new Date();
document.images.myImageNam e.src = 'http://imps.stcloudstate.edu:8002/bup' + filenum + '.gif?' + now.getTime();
}
//--></SCRIPT>
<IMG SRC="javascript:loadImage( )" NAME="myImageName">
It works by adding a different search string value after the image href causing the script to reload the image from the server each time...
<SCRIPT LANGUAGE="JavaScript"><!--
function loadImage() {
filenum = Math.round(Math.random() * 4) +1;
var now = new Date();
document.images.myImageNam
}
//--></SCRIPT>
<IMG SRC="javascript:loadImage(
ASKER
It is very nice of you, sdjjm ! But I just would like to implement this script by using
perl ONLY. If I used javascript, then my friend will not be able to call this script
by placing <img src="http://xxxxxxxxxx/cgi-bin/xx.pl">, right ?
perl ONLY. If I used javascript, then my friend will not be able to call this script
by placing <img src="http://xxxxxxxxxx/cgi-bin/xx.pl">, right ?
Ok problem 1 is that when no cache or expirey http header is received IE and NN behave in different ways depending on the mime type of the data.
As you have seen with Netscape it caches the results.
The answer is to send the no-cache pragma. However problem 2 is that because you are using the location header no other http head can be sent.
So we need to find a way to avoid using the location header.
I assume that you are using it because your images are stored in the directory above your cgi-bin.
The obvious way to address this is to output the image directly from the perl script. This would mean instead of just outputing the location you should do something like as follows:
print("HTTP/1.0 200\n")
print("Content/type image/gif\n");
print("pragma:no-cache\n\n ");
now open the gif file and output its contents directly to stdout.
HTH
steve
As you have seen with Netscape it caches the results.
The answer is to send the no-cache pragma. However problem 2 is that because you are using the location header no other http head can be sent.
So we need to find a way to avoid using the location header.
I assume that you are using it because your images are stored in the directory above your cgi-bin.
The obvious way to address this is to output the image directly from the perl script. This would mean instead of just outputing the location you should do something like as follows:
print("HTTP/1.0 200\n")
print("Content/type image/gif\n");
print("pragma:no-cache\n\n
now open the gif file and output its contents directly to stdout.
HTH
steve
ASKER
mouatts :
this is my script :
#!/usr/bin/perl
@files=("bup1.gif","bup2.g if","bup3. gif","bup4 .gif","bup 5.gif");
srand(time);
$num=int(rand(5));
print "HTTP/1.0 200\n";
print "Content/type image/gif\n";
print "pragma:no-cache\n\n";
print "\"http://imps.stcloudstate.edu:8002/$files[$num]\"\n\n";
anything wrong ? why I got a broken image, how to fix that ?
this is my script :
#!/usr/bin/perl
@files=("bup1.gif","bup2.g
srand(time);
$num=int(rand(5));
print "HTTP/1.0 200\n";
print "Content/type image/gif\n";
print "pragma:no-cache\n\n";
print "\"http://imps.stcloudstate.edu:8002/$files[$num]\"\n\n";
anything wrong ? why I got a broken image, how to fix that ?
ASKER
the image still not display
You need to open the image file read its contents then output it.
so assuming that the files are all on the same box as the CGI then you would do something like
open THISFILE $files[$num]
while <THISFILE>
{
print $_;
}
Steve
so assuming that the files are all on the same box as the CGI then you would do something like
open THISFILE $files[$num]
while <THISFILE>
{
print $_;
}
Steve
ASKER
to mouatts :
how to put this in my script
open THISFILE $files[$num]
while <THISFILE>
{
print $_;
}
I don't have clues.
how to put this in my script
open THISFILE $files[$num]
while <THISFILE>
{
print $_;
}
I don't have clues.
ASKER
can any one tell me how to put no-cache
in html. Should be in <head> ? how ? or in cgi ?
in html. Should be in <head> ? how ? or in cgi ?
ASKER
mouatts:
sorry to reject your asnwer, since I have been waiting too long to get the asnwer from you ! So, I think it will be fair and let others to answer this question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got a compiled error :
#!/usr/bin/perl
@files=("bup1.gif","bup2.g if","bup3. gif","bup4 .gif","bup 5.gif");
srand(time);
$num=int(rand(5));
print "HTTP/1.0 200\n";
print "Content-type: image/gif\n";
print "pragma:no-cache\n\n";
open (THISFILE,$files[$num]); -- I think you forgot () .
while <THISFILE>
{
print $_;
}
close(THISFILE); -- you gorgot to close ?
Here is the error message :
syntax error at banner.cgi line 12, near "while <THISFILE>"
Execution of banner.cgi aborted due to compilation errors.
#!/usr/bin/perl
@files=("bup1.gif","bup2.g
srand(time);
$num=int(rand(5));
print "HTTP/1.0 200\n";
print "Content-type: image/gif\n";
print "pragma:no-cache\n\n";
open (THISFILE,$files[$num]); -- I think you forgot () .
while <THISFILE>
{
print $_;
}
close(THISFILE); -- you gorgot to close ?
Here is the error message :
syntax error at banner.cgi line 12, near "while <THISFILE>"
Execution of banner.cgi aborted due to compilation errors.
ASKER
and how to change the code because my images are in the dir :
/home/tanc02/web-docs/mcs/ home1.gif
/home/tanc02/web-docs/mcs/
Sorry right idea, missing brackets but wrong place.
Below is the corrected code I've also added the path that you wanted. As an alternative you could place this within the list of files at the start of the routine or just append it at the point of opening
HTH
Steve
@files=("bup1.gif","bup2.g if","bup3. gif","bup4 .gif","bup 5.gif");
srand(time);
$num=int(rand(5));
print "HTTP/1.0 200\n";
print "Content-type: image/gif\n";
print "pragma:no-cache\n\n";
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
while (<THISFILE>)
{
print $_;
}
close THISFILE;
Below is the corrected code I've also added the path that you wanted. As an alternative you could place this within the list of files at the start of the routine or just append it at the point of opening
HTH
Steve
@files=("bup1.gif","bup2.g
srand(time);
$num=int(rand(5));
print "HTTP/1.0 200\n";
print "Content-type: image/gif\n";
print "pragma:no-cache\n\n";
open THISFILE,"/home/tanc02/web
while (<THISFILE>)
{
print $_;
}
close THISFILE;
ASKER
why I got the broken page.
the images is in the /home/tanc02/web-docs/mcs/
and the cgi script is in /home/tanc02/web-server/cg i-bin/
what's wrong ?
the images is in the /home/tanc02/web-docs/mcs/
and the cgi script is in /home/tanc02/web-server/cg
what's wrong ?
Try appending
exit 0;
at the end of the script;
Steve
exit 0;
at the end of the script;
Steve
ASKER
I don't know why, but if I took out these lines :
print "HTTP-1.0 200\n\n";
print "pragma:no-cache\n\n";
everything is fine.
So here is my code :
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1 .gif","con tact2.gif" ,"faculty1 .gif");
srand(time);
$num=int(rand(5));
print "Content-type: image/gif\n\n";
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
while (<THISFILE>)
{
print $_;
}
close THISFILE
can you explain to me line by line for the code below and why I need those lines :
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
while (<THISFILE>)
{
print $_;
}
close THISFILE
Thank a lot for trying to help me !
print "HTTP-1.0 200\n\n";
print "pragma:no-cache\n\n";
everything is fine.
So here is my code :
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1
srand(time);
$num=int(rand(5));
print "Content-type: image/gif\n\n";
open THISFILE,"/home/tanc02/web
while (<THISFILE>)
{
print $_;
}
close THISFILE
can you explain to me line by line for the code below and why I need those lines :
open THISFILE,"/home/tanc02/web
while (<THISFILE>)
{
print $_;
}
close THISFILE
Thank a lot for trying to help me !
ASKER
oh yeah ! what does this mean ?
$|=1;
$|=1;
tanc02:
$|=1;
This means output autoflush. I'm not certain that it has any effect here as it is normally used with pipes. It basically turns buffering off. However according to my manual it doesn't work with STDOUT.
That you took out those two lines and it worked is a bit weird. The first one should always be present but I know that you can often get away with it. So far as the pragma one is concerned it is there to prevent the browsers cacheing the image so that on a second call the get a new image and not the one from the cache.
Did you try the script with the Exit in it before you removed these two lines. If so try putting them back in and see if it still works.
So far as the code is concerned.
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
This opens the file that you have chosen randomly and assigns it a handle called THISFILE
while(<THISFILE>)
This is a condition that says do the next bit (within {})until you reach the end of the file. It also reads the file as well to establish whether EOF has been reached.
print $_;
This outputs the data that has just been read to STDOUT.
close THISFILE
This closes the file.
If this is now working can we close this question now please.
Steve
$|=1;
This means output autoflush. I'm not certain that it has any effect here as it is normally used with pipes. It basically turns buffering off. However according to my manual it doesn't work with STDOUT.
That you took out those two lines and it worked is a bit weird. The first one should always be present but I know that you can often get away with it. So far as the pragma one is concerned it is there to prevent the browsers cacheing the image so that on a second call the get a new image and not the one from the cache.
Did you try the script with the Exit in it before you removed these two lines. If so try putting them back in and see if it still works.
So far as the code is concerned.
open THISFILE,"/home/tanc02/web
This opens the file that you have chosen randomly and assigns it a handle called THISFILE
while(<THISFILE>)
This is a condition that says do the next bit (within {})until you reach the end of the file. It also reads the file as well to establish whether EOF has been reached.
print $_;
This outputs the data that has just been read to STDOUT.
close THISFILE
This closes the file.
If this is now working can we close this question now please.
Steve
Hallelujah!
Either close it, or drop back 10 and punt....
Either close it, or drop back 10 and punt....
ASKER
I have tried everyting I can, I think this is the best :
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1 .gif","con tact2.gif" ,"faculty1 .gif");
srand(time);
$num=int(rand(4));
print "Content-type: image/gif\n\n";
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
while (<THISFILE>)
{
print $_;
}
close THISFILE;
exit 0;
but if I called the script like this imps.stcloudstate.edu:8018 /cgi-bin/t ry.pl
I can see the images changed when I hit reload.
but If I tried to use <img> tag in the imps.stcloud........./try. html
and the image tag is <img src="http://imps.stcloudstate.edu:8018/cgi-bin/try.pl">
the image is changed if I hit reload just one time. And If I hit again, then the second
image will be there forever !
Any Idea, how can I improve my script.
if I included this print "HTTP/1.0 200\n";
then I will get 500 error
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1
srand(time);
$num=int(rand(4));
print "Content-type: image/gif\n\n";
open THISFILE,"/home/tanc02/web
while (<THISFILE>)
{
print $_;
}
close THISFILE;
exit 0;
but if I called the script like this imps.stcloudstate.edu:8018
I can see the images changed when I hit reload.
but If I tried to use <img> tag in the imps.stcloud........./try.
and the image tag is <img src="http://imps.stcloudstate.edu:8018/cgi-bin/try.pl">
the image is changed if I hit reload just one time. And If I hit again, then the second
image will be there forever !
Any Idea, how can I improve my script.
if I included this print "HTTP/1.0 200\n";
then I will get 500 error
OK two things
1 leave the pragma in but take the HTTP out. It should work OK.
2 Close this question.
Steve
1 leave the pragma in but take the HTTP out. It should work OK.
2 Close this question.
Steve
ASKER
leave the pragma in will cause the broken image
leave the pragma out, everything is fine in IE but not netscape.
please take a look at imps.stcloudstate.edu:8018 /try.html
leave the pragma out, everything is fine in IE but not netscape.
please take a look at imps.stcloudstate.edu:8018
OK can you post your script as it is back again.
Steve
Steve
ASKER
here is my script :
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1 .gif","con tact2.gif" ,"faculty1 .gif");
srand(time);
$num=int(rand(4));
print "Content-type: image/gif\n\n";
#print "pragma:no-cache\n\n";
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
while (<THISFILE>)
{
print $_;
}
close THISFILE;
exit 0;
the reason I would like it to work on both browser is because someonemay want to use
my img tag on his/her web-site
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1
srand(time);
$num=int(rand(4));
print "Content-type: image/gif\n\n";
#print "pragma:no-cache\n\n";
open THISFILE,"/home/tanc02/web
while (<THISFILE>)
{
print $_;
}
close THISFILE;
exit 0;
the reason I would like it to work on both browser is because someonemay want to use
my img tag on his/her web-site
Try this
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1 .gif","con tact2.gif" ,"faculty1 .gif");
srand(time);
$num=int(rand(4));
print "Content-type: image/gif\n";
print "pragma:no-cache\n\n";
open THISFILE,"/home/tanc02/web -docs/mcs/ ".$files[$ num];
while (<THISFILE>)
{
print $_;
}
close THISFILE;
exit 0;
#!/usr/bin/perl
$|=1;
@files=("home1.gif","mess1
srand(time);
$num=int(rand(4));
print "Content-type: image/gif\n";
print "pragma:no-cache\n\n";
open THISFILE,"/home/tanc02/web
while (<THISFILE>)
{
print $_;
}
close THISFILE;
exit 0;
ASKER
still the same thing, it just changed the first image, the rest images will still be the same !
I just cut and paste this code altering only the image names and the file location and it worked in IE4,Netscape 3 and Netscape 4.
With Netscape 4 I went a tep further and cleared my cache and then hit the reload button many many times whilst monitoring the cache directory. Finally I closed Netscape down again thus purging the memory cache to disk. Except nothing was written to disk! The cache remained empty throughout.
You are absolutely right that sometimes the image doesn't change but that is becuase the number being generated by random is the same in two or more consequative occassions.
This code is working as you required so there is nothing further that I can add.
Steve
With Netscape 4 I went a tep further and cleared my cache and then hit the reload button many many times whilst monitoring the cache directory. Finally I closed Netscape down again thus purging the memory cache to disk. Except nothing was written to disk! The cache remained empty throughout.
You are absolutely right that sometimes the image doesn't change but that is becuase the number being generated by random is the same in two or more consequative occassions.
This code is working as you required so there is nothing further that I can add.
Steve
ASKER
sorry to bother, I will appreciate if you can go to these site
imps/stcloudstate.edu:8018 /cgi-bin/t ry.pl
- everything is fine here, can see all the images changed.
imps.stcloudstate.edu:8018 /try.html
- only the first imgae changed. I also tried to hit reload so many many many many many time.
If you tried the site above, you will now what I mean .
once again, sorry !
imps/stcloudstate.edu:8018
- everything is fine here, can see all the images changed.
imps.stcloudstate.edu:8018
- only the first imgae changed. I also tried to hit reload so many many many many many time.
If you tried the site above, you will now what I mean .
once again, sorry !
Ok the problem appears to be with Netscape 4 (I don't know about 4.5)
With Netscape 3 it works correctly.
I have tried a number of things but N4 seems to lose track, internally, of the status of the image. If you check the page info you will see that it reckons that the image is not cached.
This is not a new bug however, although I didn't think of this until now, but with N4 if you do a reload the images don't refresh. To force that you normal do a view image and reload that then when you go back it utilises the image previously loaded.
I am afraid that I don't believe there is a way around this. Nevertheless the script is now working on other browsers.
Steve
With Netscape 3 it works correctly.
I have tried a number of things but N4 seems to lose track, internally, of the status of the image. If you check the page info you will see that it reckons that the image is not cached.
This is not a new bug however, although I didn't think of this until now, but with N4 if you do a reload the images don't refresh. To force that you normal do a view image and reload that then when you go back it utilises the image previously loaded.
I am afraid that I don't believe there is a way around this. Nevertheless the script is now working on other browsers.
Steve
ASKER
I am using Netscape 4.5.
but why I can see other peolpe web's images changed, they also used img call.
but why I can see other peolpe web's images changed, they also used img call.
Can you give me a URL that demonstrates this working.
ASKER
it is long time ago, I saw those web-site, but give me a day I will try to find it.
Mean while, I think the best example are the links that provided by LinkExchange, they use img call, right ? and the images changed everytime.
Mean while, I think the best example are the links that provided by LinkExchange, they use img call, right ? and the images changed everytime.
ASKER
it is long time ago, I saw those web-site, but give me a day I will try to find it.
Mean while, I think the best example are the links that provided by LinkExchange, they use img call, right ? and the images changed everytime.
Mean while, I think the best example are the links that provided by LinkExchange, they use img call, right ? and the images changed everytime.
I'm afraid that LinkExchange does the same thing. Try my site at www.bedrockcomputers.demon.co.uk and you wil see that the images refresh for a short time only.