Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need advice fixing ip redirect coding

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

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Code:
    <!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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • Users who have thanked itsallkizza for this post:

    JoePlumber (12-16-2008)

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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 -->

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    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.
    Last edited by Philip M; 12-16-2008 at 01:02 PM.

  • #5
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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.
    Last edited by itsallkizza; 12-16-2008 at 03:31 PM.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •