PDA

View Full Version : Passing derived address to href


Neil
10-30-2002, 09:42 AM
I have now got the IP address extraction working with help from many of you, thanks.

Now I need to get the derived URL address into the web page itself. The code I used to start with is:

<%
Dim Full_Ip, Part_IP, Specific_URL
Full_Ip = request.servervariables("remote_addr")

Part_IP = Left(Full_IP,7)

if Part_IP = "10.99.7" then
Specific_URL = "site1.htm"
end if

if Part_IP = "10.99.3" then
Specific_URL = "site2.htm"
end if

if Part_IP = "10.98.3" or Part_IP = "10.98.4" then
Specific_URL = "HeadOffice.htm"
end if

response.write(Part_Ip)
response.write(Specific_URL)

%>

Now that we have been able to identify the site and define the correct webpage to display. I now need to setup a hyperlink to go to the correct page.

Within the body of the page I want to try and do something like this:
<p><a href="Specific_URL"> Your Site Information</a></p>
</body>

However, How can I get the VBScript value in Specific)_URL to be used within the HTML?

Thanks in advance,

Neil

waj_muller
10-30-2002, 12:55 PM
Yes you can use the vbscript within the html,see below

<a href="<%=Specific_URL%>">Your site</a>

This will produce a result as follows...
<a href="HeadOffice.htm">Your site</a>

The signs <%=%> instructs the vbscript to
response.write the contents of the variable to that spot,so that when you html code gets sent to the browser it now contains you URL

Have fun.....

Neil
10-30-2002, 02:08 PM
Thanks,

That worked great.

Neil

Mhtml
10-30-2002, 09:41 PM
Just in the interests of tidy code, you may want to use SELECT CASE instead of all those if statements. It just makes it easier to read and edit in my opinion.


SELECT CASE Part_Ip
CASE "10.99.7"
Specific_Url = "site1.htm"
CASE "10.99.3"
Specific_Url = "site2.htm"
CASE "10.98.4"
Specific_Url = "headoffice.htm"
END SELECT


Just a suggestion.:)

whammy
10-31-2002, 01:39 AM
Select Case is the way to go in this situation, it's not only cleaner code, but it runs faster.

Also, consider splitting the IP address by ".".
:)

That's a bit more reliable, in many cases... but yours is probably an exception.

Since it looks like you're trying to make sure that it's only accessed locally, it probably isn't an issue, since you know how many digits and periods are in your local ip network, and you're matching the ip address to that number of characters.

In other applications, you might want to add a check that checks the first split of the array to make sure it's "10" as well, in that case, I usually do that and if anyone tries to access a page outside of the network I send them to http://www.barbie.com.

:D

Neil
10-31-2002, 11:07 AM
Thanks you all,

Your assitance has been most helpful.

Neil