How can I customize the Banned IP message in Drupal 7?

Category: Drupal

mikeb
Asked:
2012-03-26 11:04 am EST

Hits: 1,693
I was reading your article http://www.inmotionhosting.com/support/website/drupal/blocking-a-specific-ip-address-in-drupal and was wondering how you could customize the message “Sorry, 141.0.10.182 has been banned.” I'm a web developer and would like to customize that message. Do you know how?

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

Tim S.
Staff
9,967 Points
2012-03-26 11:22 am EST
Hi mikeb,

Thanks for posting your question. I'm more than happy to assist you. The code to check to see if the IP address is banned is handled in the /includes/bootstrap.inc file. You can edit the message in the code in the file to whatever you'd like. Here's the code snippet to look for in that file:

/**
* Handles denied users.
*
* @param $ip
* IP address to check. Prints a message and exits if access is denied.
*/
function drupal_block_denied($ip) {
// Deny access to blocked IP addresses - t() is not yet available.
if (drupal_is_denied($ip)) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.';
exit();
}
}



Notice, the line:

print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.';



You simply need to edit this line to whatever you'd like the banned IP address message to be.

If you need further assistance please feel free to contact us.

Thanks!

Tim S

You must login before you can post a comment about this answer.

Hi,
I came across this post while looking for information on how to translate the ip banned message in question. I hope you don't mind if I ask a couple of questions.

1) Would it be possible use settings.php in the theme to achieve the same result (instead of changing a core file)?

2) How would one make this message translatable?

Thank you in advance for any insight that you could provide!
jorgemare
6 Points
2014-03-30 8:51 pm EST
Hello jorgemare,
Unfortunately, I am unaware of a solution to change this using a theme or making it translatable. You may, however. be able to develop a custom plugin that overrides this.
JeffMa
8,502 Points
Staff
2014-03-31 8:51 am EST
JeffMa,

Thank you for they reply.

Will see if I can find a solution that does not require hacking core, and will share it here.

J
jorgemare
6 Points
2014-04-01 4:31 am EST
Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!