Solved

displaying an image based on the URL of the website

Posted on 2004-10-18
14
316 Views
Last Modified: 2010-08-05
i have a website that has 3 different urls and they are all going to the same IP
i have a single image that says the name of the site on the top of all my pages
i want to create 3 differetn images each showing a different domain name and i would like to get it so depending on the URL the person entered the site, it shows the right image so the domain and the graphic is consistent with the site name.

wondering how id write the script to check for the requested URL server variable and then have the href that displays the image swap to the appropriate version of the image based on the URL
0
Comment
Question by:khamal
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 12343319
for( $ENV{HTTP_HOST}.$ENV{REQUEST_URI} ){
  if( /pattern matching URL1/i ){
       $image="image1.gif";
  }elsif( /pattern matching URL2/i ){
       $image="image3.gif";
  }elsif( /pattern matching URL3/i ){
       $image="image1.gif";
  }else{
       $image="unknown.gif";
  }
print qq(<img src="$image">);
0
 
LVL 84

Expert Comment

by:ozo
ID: 12343321
Sorry, fogot a }
0
 

Author Comment

by:khamal
ID: 12343336
i shoul dhave specfified i need it in ASP or vbscript. >.<
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Accepted Solution

by:
CyberQuestions earned 125 total points
ID: 12344056
I have done this many times - you can become very dynamic with this type of coding.

The following example looks at the URL that was entered into the browser window and simply asks an If Contains Question to determin what image to use:

' This line get the URL that was requested
TURL = CStr(Request.ServerVariables("HTTP_HOST"))

' This code looks for the string "website1" in the URL
' ( such as http://www.website1.com/ ) and if it exeists,
' assisgnes image #1 to the SHOW_IMG Variable:
If InStr(TURL, "website1") > 0 Then
     SHOW_IMG = "image1.gif"
End If

' This line looks for the string "website2" in the URL
' ( such as http://www.website2.com/ ) and if it exeists,
' assisgnes image #2 to the SHOW_IMG Variable:
If InStr(TURL, "website2") > 0 Then
     SHOW_IMG = "image2.gif"
End If

Then, where your Graphic should be placed - use:
<img border="0" src="images/<% =SHOW_IMG %>">

Have fun, Good luck!
0
 

Author Comment

by:khamal
ID: 12344455
hm not sure what im going wrong here but this is exactly how ive tried it.

<% TURL = CStr(Request.ServerVariables("HTTP_HOST")) %>


<%If InStr(TURL, "http://www.domain1.com/") > 0 Then
     SHOW_IMG = "1.jpg"
End If%>


<%If InStr(TURL, "http://www.domain2.com/") > 0 Then
     SHOW_IMG = "2.jpg"
End If%>


<img src="plastic_images/<% =SHOW_IMG %>" width="754" height="424" border="0" usemap="#Map">

if u see anything i did wrong let me know. im still messin with it. thanks for the start!
0
 
LVL 5

Expert Comment

by:vadivhere
ID: 12344571
This code is working perfectly, there is no error. If you tell what is the error u're getting it will give us more clear picture!

Cheers!!
0
 

Expert Comment

by:CyberQuestions
ID: 12344585
OK - Try this:
In this line:
If InStr(TURL, "http://www.domain1.com/") > 0 Then

Try using less of the string to search for. For example, you could just look for "1" like this:
If InStr(TURL, "1") > 0 Then

The issue is probably that the ENTIRE string must match the InStr search so it may not be finding the last "/". InStr is command for In String so the if statement asks If "1" is in the string that is called TURL then do this.

Make sense? Can you give me the two domains that are pointed to your site?
0
 

Author Comment

by:khamal
ID: 12344723
0
 

Author Comment

by:khamal
ID: 12344735
i tried just putting part of the url in for InStr but that didnt work either.
0
 
LVL 84

Expert Comment

by:ozo
ID: 12344814
But what if someone enters
http://69.20.52.76/
0
 
LVL 84

Expert Comment

by:ozo
ID: 12344821
Try the InStr without the http://
0
 

Expert Comment

by:CyberQuestions
ID: 12344831
Can you change this line:
<% TURL = CStr(Request.ServerVariables("HTTP_HOST")) %>

to:
<%

TURL = CStr(Request.ServerVariables("HTTP_HOST"))
Response.Write(TURL)

%>

This will show us what the value of TURL is and may help us solve the problem.
0
 

Expert Comment

by:CyberQuestions
ID: 12344882
You may also want to try using this:
TURL = CStr(request.servervariables("SERVER_NAME"))

Istead of:
TURL = CStr(Request.ServerVariables("HTTP_HOST"))
0
 

Author Comment

by:khamal
ID: 12348288
thanks!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

785 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