Monitor the traffic on my website by implementing .htaccess restrictions

I am maintaining a website with restricted access to specific IP addresses listed in the .htaccess file. I am looking to implement a logging system that tracks unauthorized attempts to access the site. Is it feasible to record each attempt in a database? If identifying the IP is not possible, could I at least log the date and time of these unsuccessful access attempts? Any suggestions would be greatly appreciated. Thank you, Mor

Answer №1

If you happen to have access to the console and are working with the default settings, simply type the following command:

cat /var/log/apache2/access_log | awk '{if ($9 == 403) print $1}'

within the command line interface.

127.0.0.1 - - [03/Nov/2014:18:45:21 +0100] "GET /forbidden/test.jpg HTTP/1.1" 403 

The IP address is found in the first column, while the ninth entry (403) represents the HTTP status code. Each segment of data is separated by a space.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to examining the HTTP response body, including HTML content, using Wireshark

After entering the URL in the address bar of the virtual machine's browser, a request for an HTML document from my host computer was made. The HTML document, which I had personally written, successfully appeared in the virtual machine's browser. ...

Encountering a Node Js post handling error with the message "Cannot GET /url

This is my ejs file titled Post_handling.ejs: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>POST-Handling Page</title> </head> <body& ...

Guide to retrieving a file stored locally with VueJS

Currently, I am working on an upload system and I want to provide users with a sample template. The template is stored locally in a subfolder within the assets directory. My goal is to access this template in my VueJS component and display a link to it on ...

Encountering a vast expanse of empty white void

Attempting to create a scrollbar within my content div instead of the entire window seems to be causing a large white space in the content box, and I'm struggling to understand why. Can someone take a look and help me identify the issue? You can view ...

Is this filter vulnerable to an XSS attack?

function sanitizeInput($input){ $index=0; return str_replace("<","&lt;",str_replace(">","&gt;",str_replace("&","&amp;",$input,$index),$index),$index); } Would this method be effective in preventing XSS attacks? Just my person ...

PHP code to strip subdomain from a URL

Currently, I am using a PHP script to clean URLs from a text file. Below is the code snippet: $file = __DIR__."/url.txt"; $f = fopen($file, "r"); $array1 = array(); while ( $line = fgets($f, 1000) ) { $nl = mb_ ...

Utilizing Python Selenium to Interact with Buttons

Encountering an issue while trying to use Selenium to click on a tab or button within my web application. Below are the code snippet and CSS selectors: Error message: selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: #t ...

Error in Compiling HTML Elements Collection<<Element>

Currently, I am developing an eCommerce application that features a popup window for users when they click on "Add to Cart." This popup allows users to select product variations and quantities before adding the item to their cart. The popup consists of a s ...

Creating a Navigation Bar using the Flexbox property

As a beginner, I attempted to create a navbar using flex but did not achieve the desired outcome. My goal is to have: Logo Home About Services Contact * { margin: 0; padding: 0; font-family: ...

Tips for maintaining checkbox checked status through page reloads

Hello there! In my Laravel e-commerce store, I have a list of currency values displayed as checkboxes. When a checkbox is selected, the page reloads to update the currency value. However, the checkbox selection is lost after the page reloads. Any suggest ...

PHP fails to respond following the use of the imagedestroy function

During my development process, I encountered an issue. After using imagedestroy, my script refuses to execute certain PHP and HTML code. If I remove the header, then the PHP / HTML executes after the imagedestroy function. However, I require the header in ...

Unordered calling of functions in JavaScript - is it possible?

I'm currently working on a project that involves extracting data from an SQL database and converting the output of a query (which is a number) into a corresponding color, which is then passed to a JavaScript variable. Essentially, I am using ajax to ...

Update user login status in database following a forced browser closure or expiration of session

I have a user login data in MySQL, where users are only allowed to login once per session. The logout button works fine, but if the user closes the browser // user_table in MySQL user_id user_username user_password is_login 1 ...

Is it possible to convert HTML to PDF on the server?

A PDF file is being created from an HTML file using the princexml pdf converter package. The data for the HTML file is provided by the server. In the browser, jQuery is used to generate the input string (HTML code) for creating the PDF. Once the input stri ...

alignment not behaving as anticipated

My goal is to position two elements on different sides within a container. Although in my coding scenario, these elements are meant to be on opposite ends of a div, for the sake of explanation, let's consider them being on opposite sides of the browse ...

Verifying username using an Ajax call

Currently, I am working on developing a signup form using HTML/CSS/JS that involves utilizing an AJAX request to interact with the server. Within my jQuery code, I have implemented a method for validating the form inputs, which also triggers a function (en ...

I have exhausted all possible solutions in my attempts to eliminate the whitespace below my footer. Is there something I have overlooked or not tried yet?

After updating the CSS stylesheet, I noticed a white space below my footer. A screenshot has been included for reference. Despite including a CSS reset, the issue still persists. /* html5doctor.com Reset Stylesheet v1.6.1 Last Updated: 2010-09-17 Author ...

Ways to enable GPG keys for PHP shell_exec操作

I have encountered an issue with a script I am developing which involves running a perl script via command line using the shell_exec() function. As part of setting up the script, I had to generate a GPG key on my end and import a public key into my GPG key ...

Storing information in a JSON file

Is there a way to save data in a JSON file without using a database? I want to store questions from the user interface, but I haven't learnt about databases yet. I know using a database would be more efficient. Does anyone know if it's possible ...

Concealing and revealing template URLs with AngularJS

I am currently working with a dynamic Array in my Controller that contains templates (html files) structured similarly to the example below: $scope.templates = [ { name: 'template1.html', url: 'template1.html'}, { name: ...