Results 1 to 5 of 5

Thread: IP Redirect

  1. #1
    Join Date
    Dec 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question IP Redirect

    Before anyone tells me you can't completely ban people with JavaScript. I do know this won't work if they disable JavScript. I am not wanting to ban just redirect some IPs. A JavaScript redirect is enough for what I need.

    I have looked through tons of forums and sites. I get the same 3 or 4 types of JavaScript IP Ban/redirect. I can't do anything on the server side. I can't use PHP or shtml files. I am pretty much stuck to JavaScript, HTML, and CSS files.

    So I was thinking if a friend could host the code to view IP and I embedded it to my site it will show the IP, and apply a id to it. Then I could getElementById for the person's IP address.

    Something like this:
    Code:
    <div id="YourIP">
    <script src="http://friend's server/ip.js" type="text/javascript"></script>
    </div>
    
    <script type="text/javascript">
    var yourip = document.getElementById('YourIP')
    
    var bannedIp = new Array();
    bannedIp[0] = "##.###.###.###"
    bannedIp[1] = "##.###.###.###" 
    
    window.onload = checkVisit;
    
    function checkVisit() {
          if (yourip == bannedIp){
             Redirect();
          }
    }
    
    function Redirect(){
          location.replace('http://www.google.com/');
    }
    </script>
    I am still fairly new to JavaScript so was wondering if this even possible and I am missing something, or will this not work period?

  2. #2
    Join Date
    Mar 2008
    Posts
    218
    Thanks
    7
    Thanked 19 Times in 19 Posts

    Default

    Can you retrieve ip's with javascript?

  3. #3
    Join Date
    Dec 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by tfit View Post
    Can you retrieve ip's with javascript?
    Well my friend has it set up where I can paste a:
    <script src="http: //friend's server/ip.js" type="text/javascript"></script> like on my site from his server and it shows the IP to the person viewing... similar to the browser detection.

    Now I am not sure if the getElementById would be pulling the script link or the IP numbers.

    This is nothing important I just find that if I tinker with small things and try to get things to work I learn the stuff better. And like this just wanting to know if it's possible or not. In all honesty the $40 books you get from the stores really don't help you much in the learning process.

  4. #4
    Join Date
    Mar 2008
    Posts
    218
    Thanks
    7
    Thanked 19 Times in 19 Posts

    Default

    I can't help you, but why don't you ask your friend what he is doing on the server side? Because you can't do it javascript alone.

  5. #5
    Join Date
    Dec 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I know JavaScript alone can't do it. There has to be something SS to do it, which my first post says I do not have access to do any SS. That is why my friend has set this up with his server. I know what my friend is doing with his server and it does not help me with what I am trying to do.

    What he is doing is similar to using this:
    Code:
    <script src="http://embed.ipcatch.com/ip/" type="text/javascript"></script>
    You can put this on your web page without having SS, and it will show the viewer their IP address.

    And if I do something like:
    Code:
    <div id="YourIP">
    <script src="http://embed.ipcatch.com/ip/" type="text/javascript"></script>
    </div>
    
    <script type="text/javascript">
    var yourip = document.getElementById('YourIP')
    
    var bannedIp = new Array();
    bannedIp[0] = "##.###.###.###"
    bannedIp[1] = "##.###.###.###" 
    
    window.onload = checkVisit;
    
    function checkVisit() {
          if (yourip == bannedIp){
             Redirect();
          }
    }
    
    function Redirect(){
          location.replace('http://www.google.com/');
    }
    </script>
    when the person views the page will a "document.getElementById" grab the link (ie < script src="http://embed.ipcatch.com/ip/" type="text/javascript">< /script>) or the IP numbers?

    Cause if it grabs the numbers then this should work.

Tags for this Thread

Bookmarks

Posting Permissions

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