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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Website redirecting -- how?

    Hi, I am trying to keep a specific subdomain from seeing my webpage, something like

    192.168.X.X

    Would it be possible to have a start-up JavaScript which checks the IP and then if it falls in those ranges to redirect them to Yahoo for example, and if it doesn't then to load the website normally?

    Does anybody have code examples?


    THANKS!!!

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can't detect IP addresses thru JS as such, but you can - if it's an Apache server, that is - get the IP using the server's environment variables. you can then append that info to a JS variable and call a function which redirects based on that info.

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!!!

    How would this be done using JavaScript considering that the web server is Apache? Can anybody point me in the right direction on where I should look for a function?

    THANKS!!!

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is what you want:

    Code:
    <script type="text/javascript">
    
    	var sIp = '<!--#echo var="REMOTE_ADDR" -->' ;
    	
    	window.onload
    	{
    		switch (sIp)
    		{
    			case "SOME_IP_NUMBER": location.replace(SOME_URL_STRING); break;		
    		}	
    	}
    
    
    </script>

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by jbot
    this is what you want:

    Code:
    <script type="text/javascript">
    
    	var sIp = '<!--#echo var="REMOTE_ADDR" -->' ;
    	
    	window.onload
    	{
    		switch (sIp)
    		{
    			case "SOME_IP_NUMBER": location.replace(SOME_URL_STRING); break;		
    		}	
    	}
    
    
    </script>
    Code:
    window.onload=function()
    {
    	switch (sIp)
    	{
    		case "SOME_IP_NUMBER": location.replace(SOME_URL_STRING); break;		
    	}	
    }

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi Glenn,

    Believe it or not, the script doesn't need your addition to work. performs just fine without it.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Even if it does work, it's better to do it the normal way to avoid confusion especially for the js newbies.

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow spoil sport

    Quote Originally Posted by glenngv
    it's better to do it the normal way to avoid confusion especially for the js newbies.
    och, that spoils all the fun LOL

    you'd also be right in a readability sense, but I've gotten into the habit of writing more shortand than usual. tricks me into thinking i'm more advanced than before


  •  

    Posting Permissions

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