Solved

displaying an image based on the URL of the website

Posted on 2004-10-18
14
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
Starting up a Project

734 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