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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    TrainReq
    Guest

    Exclamation Redirecting certain IPs in a div

    How would i get this in javascript to redirect certan IPs after putting in a div..

    for example.. i do one part of it as <script src=http://www.mysite.com/ipredirector.js>

    then i choose the IPs i want to redirect by doing

    <div id=redirect style={display:hidden}>
    222.111.222.333
    444.222.112.234
    </div>

    that will then redirect those 2 IPs to another page if they come to the page with the JS file/div on it to a new page. And at any time if i want to add a new IP/change the IP... i edit the IPs listed in the div. I know it wil have to do something with "if(document.getElementById('redirect'))" and with "window.replace" or something of that nature. I have the basic programming to redirect IPs, but that requires actualy placeing the IPs in the JS file itself, i'd rather have the JS file rab the IPs out of the DIV. I've seen it done before.

    How would i go about doing that?
    Last edited by TrainReq; 12-02-2006 at 12:21 AM.

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    you can run a while loop through the contents of the div, and for every element (ip addy) do something. in this case redirect.

    right now all you have are textnodes. I personally do not like to deal with textnodes by themselves. sometimes you get ghost textnodes within your document. so i always put my text within a span or something similar.

    <div id=ip style="display:none;">
    <span>222.111.222.333</span>
    <span>444.222.112.234</span>
    <span>112.234.444.255</span>
    </div>
    and the script to go through all that would be as so:

    <script type=text/javascript>
    var ip=document.getElementById('ip');
    var spans=ip.getElementsByTagName('span'); //this is an array of all the spans within the div "ip"
    lenght=spans.length;
    i='0';
    while(i<spans.length){
    //have it do what you want here
    alert(spans[i].innerHTML);
    i++;
    }
    </script>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    TrainReq
    Guest
    I see how it alerts the IPs that you put in the span, but how would i get it to redirect the IPs in the span... lets say to www.google.com
    Last edited by TrainReq; 12-03-2006 at 12:07 AM.

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    you really need a severside script to do that.
    like asp or php.

    to my knowledge you cannot obtain a persons ip address with javascript on the client side.

    the below is an example of how to obtain such things with VBscript/asp.
    the file must have a .asp extention and the server the file is on must support asp.
    Code:
    <html>
    <body>
    <p>
    <b>You are browsing this site with:</b>
    
    <%Response.Write(Request.ServerVariables("http_user_agent"))%>
    </p>
    <p>
    <b>Your IP address is:</b>
    <%Response.Write(Request.ServerVariables("remote_addr"))%>
    </p>
    <p>
    <b>The DNS lookup of the IP address is:</b>
    <%Response.Write(Request.ServerVariables("remote_host"))%>
    </p>
    <p>
    <b>The method used to call the page:</b>
    <%Response.Write(Request.ServerVariables("request_method"))%>
    </p>
    <p>
    <b>The server's domain name:</b>
    <%Response.Write(Request.ServerVariables("server_name"))%>
    </p>
    <p>
    <b>The server's port:</b>
    <%Response.Write(Request.ServerVariables("server_port"))%>
    </p>
    <p>
    <b>The server's software:</b>
    <%Response.Write(Request.ServerVariables("server_software"))%>
    </p>
    </body>
    </html>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #5
    TrainReq
    Guest
    Actualy you can... it is like this

    Code:
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    
    if (ip == "111.111.111.111");
    if (ip == "222.222.2222.222");
    if (ip == "333.333.3333.333");
    {
    url=("http://www.google.com");
    window.location=url;("http://www.google.com");
    }
    But, how do i intergrade that with the code that you gave me above..and like do something like this

    Code:
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    
    if (ip == "GET CONTENT FROM FIRST SPAN IN DIV");
    if (ip == "GET CONTENT FROM SECOND SPAN IN DIV");
    if (ip == "GET CONTENT FROM THIRD SPAN IN DIV");
    {
    url=("http://www.google.com");
    window.location=url;("http://www.google.com");
    }
    Last edited by TrainReq; 12-03-2006 at 04:13 AM.

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Code:
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    the above is not clientside javascript. it is part of a script that runs on the server side, and when the users goes to the page the serverside script writes the ip value into the value of the variable. are you running serverside scripting? good way to check would be to insert an alert right after setting the variable ip.

    alert(ip);

    ifyou are running serverside scripting it should be an actual ip address, if not it will alert you : <!--#echo var="REMOTE_ADDR"-->. in this case it wont work.


    but if it is working you can check the ip's in the div to the ip variable like such:



    Code:
    <html>
    <body>
    <div id=ipa style="display:none;">
    <span>222.111.222.333</span>
    <span>444.222.112.234</span>
    <span>112.234.444.255</span>
    </div>
    </body>
    
    <script type=text/javascript>
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    var ipa=document.getElementById('ipa');
    var spans=ip.getElementsByTagName('span'); //this is an array of all the spans within the div "ip"
    lenght=spans.length;
    i='0';
    while(i<spans.length){
    if(spans[i].innerHTML==ip){
    window.location="http://www.google.com";
    }
    i++;
    }
    </script>
    </html>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #7
    TrainReq
    Guest
    It works fine if i manualy place the IPs in the div (like the one in the first code i placed in my above code)....but the code you gave me does not work... i think you must of typoed something, etc... BTW: I nominated you as helpful member, BrandonH
    Last edited by TrainReq; 12-03-2006 at 04:27 AM.

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    sorry about that, there is a typo. here is the fix:

    Code:
    <html>
    <body>
    <div id=ipa style="display:none;">
    <span>222.111.222.333</span>
    <span>444.222.112.234</span>
    <span>112.234.444.255</span>
    </div>
    </body>
    
    <script type=text/javascript>
    var ip = '444.222.112.234';
    var ipa=document.getElementById('ipa');
    var spans=ipa.getElementsByTagName('span'); //this is an array of all the spans within the div "ip"
    lenght=spans.length;
    i='0';
    while(i<spans.length){
    if(spans[i].innerHTML==ip){
    window.location="http://www.google.com";
    }
    i++;
    }
    </script>
    </html>

    noticed i set the ip variable to an actualy i[p address that is in the div. i did this to show that the script works. you will need to replace the value with your way of getting the ip.
    Last edited by brandonH; 12-03-2006 at 04:47 AM.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #9
    TrainReq
    Guest
    sup with this

    Code:
    var ip = '444.222.112.234';
    I think that is if i wanted to manualy put an IP in.. i want it to grab the IP with
    [code]var ip = '<!--#echo var="REMOTE_ADDR"-->';[/code}
    and basicly say: If IPs that are in span, redirect to www.google.com

  • #10
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    i set the variable to an ip addres sthat is in the div, just to prove it works. you should replace that with your:

    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #11
    TrainReq
    Guest
    still does not work... here is the code that i am using:

    Code:
    <html>
    <body>
    <div id=ipa style="display:none;">
    <span>222.111.222.333</span>
    <span>221.22.111.222</span>
    <span>112.234.444.255</span>
    </div>
    </body>
    
    <script type=text/javascript>
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    var ipa = document.getElementById('ipa');
    var spans=ipa.getElementsByTagName('span'); //this is an array of all the spans within the div "ip"
    lenght=spans.length;
    i='0';
    while(i<spans.length){
    if(spans[i].innerHTML==ip){
    window.location="http://www.google.com";
    }
    i++;
    }
    </script>
    </html>
    With my IP in the first span, doesnt redirect me.... but if i do this

    Code:
    <script>
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    
    if (ip == "111.111.111.111");
    
    
    {
    url=("http://www.google.com");
    window.location=url;("http://www.google.com");
    } 
    </script>
    With my IP replaceing 111.111.111.111 , it redirects me just fine (so it prooves that the var IP thing works, but ur code with the span thing is not. I dont know what is wrong here :S

  • #12
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    with what you are using:

    Code:
    <script>
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    
    if (ip == "111.111.111.111");
    {
    url=("http://www.google.com");
    window.location=url;("http://www.google.com");
    } 
    </script>
    you aren't actually doing a proper if statement.

    it should look like this:

    Code:
    <script>
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    
    if (ip == "111.111.111.111"){
    url=("http://www.google.com");
    window.location=url;("http://www.google.com");
    } 
    </script>
    with what you were using you werent actually doing an if statment, it was just seeing the window.location=url , and executing.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #13
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    there was a similar post that you can take a look at if you like:

    http://www.codingforums.com/showthread.php?p=23517

    same ersults though.
    client side javascript is not able to detect a user ip address.
    a serverside script must be used to insert a value into the variable within the javascript.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #14
    TrainReq
    Guest
    EDIT: My appologizes.. the server i am putting it on does not support '<!--#echo var="REMOTE_ADDR"-->';

    I saw one person do it, and it was part JS and part PHP that made the IPs in the div redirect. Have any idea how to do that? (I can put the JS part of it on the server itself, but i would need to put the PHP part on another server).

    Here is an example of how it is done... this is a myspace tracker, and it can be turned into a blocker if
    Code:
    <div id="blkr" ...
    is placed in

    here is the JS file he is using to load on myspace
    http://imaqeshack.us/image2.js
    notice how it says if blocker ID (or something like that).. call upon this
    http://www.imaqeshack.us/track2.php?...=Jon&blocker=1

    and that ends up leading on calling upon this
    http://www.imaqeshack.us/track2.php?...&blocker_url=1 (wich makes them redirect to
    http://www.myspace.com/error.aspx

    I got the javascript on loading straighted out (so dont give me anything about "Cant load JS on myspace" .. because i know how to dodge the filters... i just need to know what to put in my JS/PHP if i want the redirect function to work...

    I dont know if that can help you or not.. but i was atleast wonering instead of doing "<!--#echo var="REMOTE_ADDR"-->" do something that grabs their IP from my serverside PHP instead.
    Last edited by TrainReq; 12-03-2006 at 11:38 PM.

  • #15
    TrainReq
    Guest
    I know someoen here knows how to do this


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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