Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 14th, 2016, 06:03 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Go to different page based on user's ip address

In my classic asp form page, I am able to create javascript to identify a user's ip address:

<script type="text/javascript">
var ip = "<%=Request.ServerVariables("REMOTE_ADDR")%>";
var intEnt = ip.substring(0,ip.lastIndexOf("."));
var intraIP = "192.168.1";
if (intEnt != intraIP) {
locat = "External";
}
else {
locat = "Internal";
alert(locat);
}
</script>
I need to figure out how I can access the client side variable locat (or use some other method) to go to a page for internal users instead of a page for external users that shows less information when the form is submitted.
Reply With Quote
  #2 (permalink)  
Old January 14th, 2016, 11:52 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Thi is really a Javascript question and is probably posted in the wrong place. This should work for you:

Code:
if (intEnt != intraIP) {
	locat = "External";
	location.href= 'http://theURLForExternalPeople/thePage.asp?locat=' + locat + '' ;
}
else {
	locat = "Internal";
	location.href= 'http://theURLForInternalPeople/thePage.asp?locat=' + locat + '' ;
}
__________________
Wind is your friend
Matt

Last edited by mat41; January 15th, 2016 at 02:08 AM.
Reply With Quote
  #3 (permalink)  
Old January 15th, 2016, 12:01 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Go to different page based on user's ip address

Thanks for the reply. So I guess I'm having issues on how to get the javascript to execute. I've tried:
function CheckIP() {
...
if (intEnt != intraIP) {
locat = "External";
alert(locat);
location.href= "http://theURLForExternalPeople/thePage.asp?parcelnumber=" + parcel ;
}
else {
locat = "Internal";
alert(locat);
location.href= "http://theURLForInternalPeople/thePage.aspparcelnumber=" + parcel ;
}

<form name="bdcform" onsubmit="CheckIP()">
<input name="parcelnumber" type="text" id="parcelnumber" size="8" maxlength="8">
<input type="button" name="Submit" value="Go">
&nbsp;&nbsp;
<input name="Reset" type="reset" id="Reset" value="Reset">
</form>

with variations of onsubmit on the form or onclick on the button. I'm actually know that I'm executing the function because I'm getting the alert, but after clicking on the button, it doesn't go to a new page.
Reply With Quote
  #4 (permalink)  
Old January 17th, 2016, 07:45 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

This code can not have worked as you are missing the a closing } from your CheckIP function. I have returned false in the function and changed the onSubmit call. This should work for you no problem:

Code:
<script>
function CheckIP() {
	if (intEnt != intraIP) {
		locat = "External";
		alert(locat);	
		window.location.href= "http://theURLForExternalPeople/thePage.asp?parcelnumber=" + parcel ;
		return false;
	}
	else {
		locat = "Internal";
		alert(locat);	
		window.location.href= "http://theURLForInternalPeople/thePage.aspparcelnumber=" + parcel ;
		return false;
	}
}
</script>

<form name="bdcform"  onsubmit="return CheckIP(this);">
<input name="parcelnumber" type="text" id="parcelnumber" size="8" maxlength="8">
<input type="button" name="Submit" value="Go">
&nbsp;&nbsp;
<input name="Reset" type="reset" id="Reset" value="Reset">
</form>
__________________
Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old January 19th, 2016, 12:52 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Go to different page based on user's ip address

Thanks for your reply.
Sorry I didn't copy and paste correctly.
I changed my code to mirror yours (except I think I need input type="submit" name="Submit)
and I'm still getting the alert, but it still stays on the original page rather than going to the new page. Here is my entire test page. Does it work for you?

<html>
<head>
<title>IP Test</title>
</head>

<body>
<script>
function CheckIP() {
var ip = "<%=Request.ServerVariables("REMOTE_ADDR")%>";
var intEnd = "<%=Request.ServerVariables("REMOTE_ADDR")%>";

var intEnd = ip.substring(ip.lastIndexOf("."));
var intEnt = ip.substring(0,ip.lastIndexOf("."));
var intraIP = "192.168.1";

if (intEnt != intraIP) {
locat = "External";
alert(locat);
window.location.href="http://theURLForExternalPeople/thePage.asp?parcelnumber=" + parcel;
return false;
}
else {
locat = "Internal";
alert(locat);
window.location.href= "http://theURLForInternalPeople/thePage.asp?parcelnumber=" + parcel;
return false;
}
}
</script>

<form name="bdcform" onsubmit="return CheckIP(this);">
<input name="parcelnumber" type="text" id="parcelnumber" size="8" maxlength="8">
<input type="submit" name="Submit" value="Go">
&nbsp;&nbsp;
<input name="Reset" type="reset" id="Reset" value="Reset">
</form>
</body>
</html>
Reply With Quote
  #6 (permalink)  
Old January 19th, 2016, 08:49 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

When I look closer I cant see anywhere you have declared parcel so that should give you issues......

Is there any reason you are doing this redirect on the client side? I would do it on the server side, this will work 100% for you:

Code:
<%
    dim ipToCheck, incomingIP
	if request.form("parcelnumber") <> "" then
		ipToCheck = "172.20.60.121"
		incomingIP = request.ServerVariables("REMOTE_ADDR")
		if ipToCheck <> incomingIP then
			response.redirect("http://theURLWhereNOTEqualTo.com?parecelNum=" & request("parcelnumber"))
		else
			response.redirect("http://theURLWhereISEqualTo.com?parecelNum=" & request("parcelnumber"))
		end if
	else
	    response.write "Going no where becasue 'parcelnumber' was blank "
	end if
%>
<html>
 <head>
  <title>IP Test</title>
</head>
<body>
    <form name="bdcform" id="bdcform" method="post" onsubmit="return CheckIP(this);" >
    <input name="parcelnumber" type="text" id="parcelnumber" size="8" maxlength="8">
    <input type="submit"  value="Go">
    &nbsp;&nbsp;
    <input name="Reset" type="reset" id="Reset" value="Reset">
    </form>
</body>
</html>
__________________
Wind is your friend
Matt
Reply With Quote
  #7 (permalink)  
Old January 20th, 2016, 12:45 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Go to different page based on user's ip address

Thanks again for your reply. It's working!!!
I had started down the client side path because I had a need to strip the last characters from the ip address, and had figured out some javascript to do that. If only I had figured out the server side script first, then I wouldn't have headed into that direction and the confusion. This is the final code:

<%
dim ipToCheck, incomingIP, pos, lastpt, strippedIP
if request.form("parcelnumber") <> "" then
ipToCheck = "192.168.1"
incomingIP = request.ServerVariables("REMOTE_ADDR")
response.write incomingIP
pos = InStrRev(incomingIP, ".")
lastpt = Mid(incomingIP, pos)
strippedIP = Replace(incomingIP, lastpt, "")
if ipToCheck <> strippedIP then
response.redirect("http://theURLWhereNOTEqualTo.com?parcelnumber=" & request("parcelnumber"))
else
response.redirect("http://theURLWhereISEqualTo.com?parcelnumber=" & request("parcelnumber"))
end if

end if
%>
<html>
<head>
<title>IP Test</title>
</head>

<body>

<form name="bdcform" id="bdcform" method="post" onsubmit="return CheckIP(this);" >
<input name="parcelnumber" type="text" id="parcelnumber" size="8" maxlength="8">
<input type="submit" value="Go">
&nbsp;&nbsp;
<input name="Reset" type="reset" id="Reset" value="Reset">
</form>
</body>
</html>

Thanks again for your help!
Reply With Quote
  #8 (permalink)  
Old January 20th, 2016, 07:06 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Thats great im an please its working for you. IMO an ASP approach is much better for so many reasons. The most important is someone firing up firebug or Chromes inspector and fiddling with your code. JS is so exposed, also it may not even be active in the uses browser, then you have different brosers Document Object Model so your code may work in Chrome but not IE, then does it work in previous versions of certain browsers......... have I said enough to convince you?????

Here is the code you need to get the the last x characters from a string. Simply the bult in right function

Code:
dim ip
ip = trim(request.ServerVariables("REMOTE_ADDR"))
response.write ip & " = the original IP<BR>"
response.write right(ip, 2) & " = last 2 characters<BR>"
response.write right(ip, 3) & " = last 3 characters<BR>"
__________________
Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me i must Get IP Address pla_2 C# 2005 2 October 12th, 2006 08:51 AM
IP Address sumanghosh Classic ASP Basics 1 April 7th, 2006 12:24 PM
How to get IP address shankhan Classic ASP Databases 6 March 10th, 2005 04:18 PM
Retreiving IP address & gateway address sjangit VBScript 0 February 3rd, 2004 02:02 PM



All times are GMT -4. The time now is 03:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.