Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Banning Script

Featured Replies

Hey,

 

could someone make a banning script for me ? I don't know how to make one, I've googled for one but they are all crap.

 

Thanks.

I like it when a client goes deeply into specifics.

 

;)

 

Talking of which, it might help if you list a few few specifics like:

What do you want to ban, from where and how.

^ lol

 

IN CASE you are looking to ban an IP (don't moan if this isn't what you're looking for!)

 

<?php

$ban = "127.0.0.1"; //IP to ban

if($_SERVER['REMOTE_ADDR'] == $ban){
echo 'DENIED!!'; exit;
}

?>

 

Obviously, if you have tried a few already, it is more than likely you have come across something like this. Pretty crap!

^ lol

 

IN CASE you are looking to ban an IP (don't moan if this isn't what you're looking for!)

 

<?php

$ban = "127.0.0.1"; //IP to ban

if($_SERVER['REMOTE_ADDR'] == $ban){
echo 'DENIED!!'; exit;
}

?>

 

Obviously, if you have tried a few already, it is more than likely you have come across something like this. Pretty crap!

 

 

Nice bit of cheeky code there Shaun! :pp..... isnt it nearly impossible to bann most people as the majority of peeps have changing IP addresses.

  • Author

Yes, this looks quite the same I've found.

 

I don't want to ban IP ranges, only IP addresses. I want to integrate this in my ACP, and make script that allows me just to enter any IP address and it automatically bans it ( I think I know how to do this ). Then I also need to be able to remove the ban.

 

I've found a banning script, like the one you just showed me, where you have an empty page with a line that says that you've been banned or whatever else you would like to appear on the page. But I want the whole page of the site to appear ( that looks like the rest of the site ) with a line that says "You are not allowed to visit this site" or something like that, but, as I said, I want the page to keep like the other pages, with the menu, header, footer, etc.. and this line would be at the place of the usual content.

 

Thanks in advance,

REVS.

If your server supports .htaccess files, it will be best to make a script that disallows them through .htaccess rather than your PHP code.

Ideally, we would need to see the code and perhaps your website structure...

Can you not use your hosting company's cpanal (or equivalent) to block IPs?

  • Author

No I don't have this. And I want my own one :p. So ... is it too difficult ? Too complicated ? :(

  • Author

<?php

$ban = "127.0.0.1"; //IP to ban

if($_SERVER['REMOTE_ADDR'] == $ban){
echo 'DENIED!!'; exit;
}

?>

 

Okay I will take this and modify it. But I want a particular page to appear, not just a line on an empty page, how do I do that ?

 

I guess I have to change something here :

 

echo 'DENIED!!'

 

How can I include a whole page in this ?

You might be able to use PHPs include'file.php'; command...?

 

Eg:

 

<?php
$ban = "127.0.0.1"; //IP to ban

if($_SERVER['REMOTE_ADDR'] == $ban)
{
   [b]include 'index.php';    [/b]
   echo 'DENIED!!'; exit;
}
?>

 

You can change the file name to a page on your site that suits. I think it'll still boot the user if you have the EXIT; command after the include, but someone should confirm if I'm on the right / wrong track.

 

Jarrad

  • Author

It works, thanks very much ! :)

 

Also, I removed the echo 'DENIED!!';.

  • Author

Okay so here's the next problem : I've created a page in my ACP that allows me just to enter any IP and then to click on the submit button to ban it. Everything seems to work there just I don't get banned when I enter my IP.

 

My table in the DB is called banning.

 

Here's what I have on the banning script :

 

<?php
mysql_connect("localhost", "root", "root");
mysql_select_db("MM");

$ban = $donnees['ip'];

if($_SERVER['REMOTE_ADDR'] == $ban)
{
include 'banned.php'; exit;
}
?>

 

I don't know how to connect to take out the data from the table banning.

In the table banning I have : id ( INT, primary, auto-increment ) and ip ( varchar ( 15 characters max. ) ).

 

So my problem is to import the data from this table, I just don't know how. I don't know if you understand my problem.

 

Anyways, thanks in advance.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.