Solved

displaying an image based on the URL of the website

Posted on 2004-10-18
14
313 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
Comment Utility
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
Comment Utility
Sorry, fogot a }
0
 

Author Comment

by:khamal
Comment Utility
i shoul dhave specfified i need it in ASP or vbscript. >.<
0
 

Accepted Solution

by:
CyberQuestions earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:khamal
Comment Utility
0
 

Author Comment

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

Expert Comment

by:ozo
Comment Utility
But what if someone enters
http://69.20.52.76/
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Try the InStr without the http://
0
 

Expert Comment

by:CyberQuestions
Comment Utility
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
Comment Utility
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
Comment Utility
thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

12 Experts available now in Live!

Get 1:1 Help Now