We are trying this tutorial to be simple, so in this page we will request imagenes from a ".asp" page, but the imagen will not be newly generated. The images will be already saved in our server .
First, let´s check this two pages:
| showpicture.html | |
| <html> <title>My picture</title> <body> <img src=mypicture.asp> </body> | 1 2 3 4 5 6 7 8 |
| mypicture.asp | |
| <% response.ContentType ="image/GIF" %> <!--#include virtual="mypicture.gif" --> | 1 2 |
- In the first file (showpicture.html) we have include in the html code the source for our picture ("mypicture.asp", instead of "mypicture.gif").
- In the response page, first we have indicated whith kind of ContentType we are sending to the client (this time "image/GIF", and then by using "include/virtual" the file is send (in this case all files are in the same directory)
Let´s try an examples:
A rudimentary banner rotator system
Our page is "mypage.html" and we are requesting a picture to a file named "mypicture.asp". This file will send to the client one of the pictures available (in this case up to 5), and two variables will be set up:
- session ("ad"): will be used to save a number, which is needed to determinate which ad to show each time
- session ("linkto"): will be used to save the link corresponding to the ad shown.
| mypage.html | |
| <html> <title>My page</title> <body> <a href=adrotatorlink.asp><img src=mypicture.asp NOSAVE></a> </body> | 1 2 3 4 5 6 7 8 |
| mypictureasp | |
| <% if session("ad")="" then session("ad")=0 end if if session("ad")=5 then response.ContentType ="image/GIF" <% Select Case session("ad") %> | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
| adrotatorlink.asp | |
| response.redirect(session("linkto")) | 1 |
"mypage.html"
At "mypage.html" we have include the regular HTML code to show a picture. We have used within the code the instruction "NOSAVE", so the picture will not be saved in the clients cache.
"mypicture.asp"
- Lines 2-3. Each time a new visitor gets to "http://www.myadrotator.com/adrotator.asp" a new session will be open, and by using the session method, we will define session("ad") value to 0. In case the visitor is not new, the value for session("ad") will exits, and that value will be keep.
- Lines 6-10. The value for Session("ad") is increased by one unless that value is 5 (which is the maximum value allowed in this script)
- Line 12. The ContentType is defined
- Lines 15-31. By using Select_case and depending on the value saved in the instruction session("ad"), we will define session("linkto"), which will be the url to which we will redirect our visitor in case the picture send to the browser is clicked.
After clicking the corresponding picture, and as we have already save the corresponding URL at session('linkto"), we will redirect the visitor to the correct URL.NOTE: By using "NOSAVE" code in our page, the client will no save the picture in the cache of the computer. It may be a problem for us: let´s suppose we have include this the same code in several pages within our site. Each time we visit a new page, session ("linkto") will be defined again, but in case the visitor clicks the back bottom of the browser and the picture show is the same one it was shown in our previous visit, when clicking the visitor will be redirect to a non-correct URL.
discuss this topic to forum
