...

View Full Version : Need advice fixing ip redirect coding



JoePlumber
12-13-2008, 03:28 AM
I am using the code pasted in below but I have noticed that this code redirects EVERY IP address. I only want the code to redirect 25 specific IP addresses.

I do not know HOW to add in the multiple IP addresses because I don't know if a semicolon separates the IP addresses or quotations and a semicolon or a comma, or quotations and a comma.

Also, I do not have access to the server so I can't use any code that requires it. This is why I am using a client-side Javascript solution currently.

Thanks for the help,
Joe P.


<!--#if expr="${REMOTE_ADDR} = /12.34.567.89/" -->
<script language="javascript">
alert("You are being redirected.");
if (confirm("Thank you."))
{location.href="http://www.google.com” } else { ("Viewing access denied."); {location.href="http://www.msn.com" }}
</script>
<!--#endif -->


I was told to change the code to this ...but it does not work correctly:
<script language="javascript">
if("<!--#echo var="REMOTE_ADDR"-->" == "12.34.567.89"){
alert("You are being redirected.");
if (confirm("Thank you."))
{location.href="http://www.google.com” } else { ("Viewing access denied."); {location.href="http://www.msn.com" }}
</script>
<!--#endif -->

itsallkizza
12-13-2008, 05:26 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example</title>
<style type="text/css">
</style>
<script type="text/javascript">
// <![CDATA[

var ips_to_redirect = [
"12.34.567.89",
"12.34.567.90",
"12.34.567.91",
"12.34.567.92",
"12.34.567.93"
];

//Default SI Language
var ip = "<!--#echo var="REMOTE_ADDR"-->";

//PHP
//var ip = <?php echo(@$REMOTE_ADDR); ?>;

//ASP
//var ip = <% response.write(request.ServerVariables("REMOTE_ADDR")) %>

function array_contains(arr,what)
{
for (var i=0;i<arr.length;i++)
{
if (arr[i] == what) return true;
}
return false;
}

if (array_contains(ips_to_redirect,ip)) location = "http://www.youreontheviplist.com";
else location = "http://www.notonthelist.com";

// ]]>
</script>
</head>
<body>


</body>
</html>


Note:


<!--#echo var="REMOTE_ADDR"-->

is in fact server-side - it's not Javascript.

JoePlumber
12-16-2008, 11:33 AM
Hello again!

Thanks for the help. Your time is greatly appreciated.

The code you suggested has been installed and tested and I added my own IP address. The IP was not redirected.

As I mentioned, this code below WORKS but it works too well!
It redirects every IP.

The reason why I was using the code below is because I am only able to use Javascript since I don't have access to the server.

<!--#if expr="${REMOTE_ADDR} = /12.34.567.89/" -->
<script language="javascript">
alert("You are being redirected.");
if (confirm("Thank you."))
{location.href="http://www.google.com” } else { ("Viewing access denied."); {location.href="http://www.msn.com" }}
</script>
<!--#endif -->

Philip M
12-16-2008, 11:39 AM
This works fine for me:-


<script type="text/javascript">

var arr = [
"12.34.567.89", // list of ips to redirect
"12.34.567.90",
"12.34.567.91",
"12.34.567.92",
"12.34.567.93"
];


//Default SI Language
//var ip = "<!--#echo var="REMOTE_ADDR"-->";

//PHP
//var ip = <?php echo(@$REMOTE_ADDR); ?>;

//ASP
//var ip = <% response.write(request.ServerVariables("REMOTE_ADDR")) %>

var ip= "12.34.567.93" // for testing only
var rdFlag = 0;

function array_contains() {
for (var i=0; i<arr.length; i++) {
if (arr[i] == ip) {
alert ("On the redirect list"); // delete after testing
rdFlag = 1;
}
}
if (rdFlag == 0) {
window.location = "http://www.mysite.com/mypage.html";
}
else { // if user is on redirect list
window.location = "http://www.mysite.com/myotherpage.html";
}
}

array_contains();

</script>


You have: else { ("Viewing access denied.")
Should be else { alert ("Viewing access denied.") }

Note: www.mysite.com/mypage.html and www.mysite.com/myotherpage.html are real web pages which I often find useful for testing purposes.

itsallkizza
12-16-2008, 02:28 PM
Both my script and Philip's work for me when I enter my IP into the list.

Note: You obviously have to change the location redirects - youreontheviplist.com doesn't exist.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum