Forum Moderators: coopster

Message Too Old, No Replies

GoDaddy's Website Tonite - Help with Blocking IP Addresses

         

gouri

3:40 pm on Sep 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone know with GoDaddy's Website Tonite program what can I do to block IP addresses? They were saying that with Website Tonite you may not be able to access the .htaccess file.

There has to be some way to block IP addresses?

shogun_ro

11:31 pm on Sep 30, 2008 (gmt 0)

10+ Year Member



<?
$targetAddr = "202.46.129..*"; //yes is two dots\
$targetAddr2 = "222.124.224.147" ;
if (ereg($targetAddr, $_SERVER['REMOTE_ADDR']) ¦¦
ereg($targetAddr2, $_SERVER['REMOTE_ADDR']))
{ //remote address match, do something or don't do anything
header( 'Location: http://example.com) ;}
?>

Search onn Google for block ip php script

[edited by: martinibuster at 3:09 am (utc) on Oct. 1, 2008]
[edit reason] Examplified. [/edit]

gouri

12:31 am on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's here because if you have ads on your sites you want to block your own IP address.

Shogun,

Can you please explain to me what you wrote? Also, where would I put this code? And, where in the code that you wrote does the block ip php script go?

Thanks.

gouri

1:33 am on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In my last response I didn't mean to just provide a brief answer and just pose a series of questions.

What I am trying to say is, if possible, I would appreciate if you could please help me with what I wrote.

Thanks.

gouri

2:14 pm on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would appreciate if someone could please help me with this. I think GoDaddy's Website Tonite does not allow PHP scripting so if anyone can think of another way to accomplish this it would really be helpful?

PHP_Chimp

9:19 pm on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you cant use php to solve the problem then you may well be asking on the wrong forum. You could do something similar with javascript, however it would be pointless as people will just turn it off.
You could do the same thing with perl or java (I guess asp or any other script or programming language), however if you are not allowed to use php then a server side solution may well not work for you.

I would try the above code with <?php to start. I would also add your IP address so that you can check that the code works.

An explanation of the code:


1 <?php
2 $targetAddr = "202.46.129..*"; //yes is two dots
3 $targetAddr2 = "222.124.224.147" ;
4 if (ereg($targetAddr, $_SERVER['REMOTE_ADDR']) ¦¦
5 ereg($targetAddr2, $_SERVER['REMOTE_ADDR']))
6 { //remote address match, do something or don't do anything
7 header( 'Location: http://example.com) ;}
8 ?>

Line 1- Changed to read <?php as <? may not work if short tags are not allowed. This tells the server that what follows is php, not html or any other language.

Lines 2 and 3- are variables (things that start with $ are variables) that are providing IP addresses. The $targetAddr is defining an address that is 202.46.129.anything as the .* means any character 0 or more times.

<note>
The . is any character, so they should be escaped when you want a literal . so \. is a literal .
* is 0 or more, so should not be used in places where you need characters. The + is 1 or more, so would be better used here.
</note>

Line 4- if statement. This statement is checking the two target address variables against the remote address provided to the server.

Line 7- if the remote addresses match then you redirect the browser to example.com.

Line 8- end of php.

gouri

10:37 pm on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wanted to use this for my own computer's IP address so is javascript something that can possibly be used? Also, how would I put this script into my host account? Would I be able to create a .htaccess file in notepad and then upload it?