Solved

displaying an image based on the URL of the website

Posted on 2004-10-18
14
314 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now