<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rahul Alam</title>
    <description>The latest articles on Forem by Rahul Alam (@rahulalam31).</description>
    <link>https://forem.com/rahulalam31</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1190617%2F109ff992-2599-4018-9db6-e2c282dd25f0.webp</url>
      <title>Forem: Rahul Alam</title>
      <link>https://forem.com/rahulalam31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rahulalam31"/>
    <language>en</language>
    <item>
      <title>Preventing Spammers in Laravel: Using rahulalam31/laravel-abuse-ip Package</title>
      <dc:creator>Rahul Alam</dc:creator>
      <pubDate>Mon, 22 Jul 2024 16:31:02 +0000</pubDate>
      <link>https://forem.com/rahulalam31/preventing-spammers-in-laravel-using-rahulalam31laravel-abuse-ip-package-j0l</link>
      <guid>https://forem.com/rahulalam31/preventing-spammers-in-laravel-using-rahulalam31laravel-abuse-ip-package-j0l</guid>
      <description>&lt;p&gt;In today's digital age, protecting your Laravel applications from spam and malicious IP addresses is paramount. Spam can degrade the user experience and pose security risks. Fortunately, the &lt;a href="https://github.com/rahulalam31/Laravel-Abuse-IP" rel="noopener noreferrer"&gt;rahulalam31/laravel-abuse-ip&lt;/a&gt; package offers a robust solution to block requests from known spam IPs. This guide will walk you through setting up and using this package to safeguard your Laravel application effectively.&lt;br&gt;
Why Block Spam IPs?&lt;/p&gt;

&lt;p&gt;Before diving into the implementation, let’s understand why blocking spam IPs is crucial:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enhanced Security: Blocking known spam IPs prevents potential security threats.&lt;/li&gt;
&lt;li&gt;Improved Performance: Reducing spam traffic can improve your application's performance.&lt;/li&gt;
&lt;li&gt;Better User Experience: Keeping your application spam-free ensures a seamless experience for genuine users.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 1: Install the Package
&lt;/h2&gt;

&lt;p&gt;First, add the &lt;a href="https://github.com/rahulalam31/Laravel-Abuse-IP" rel="noopener noreferrer"&gt;rahulalam31/laravel-abuse-ip&lt;/a&gt; package to your Laravel project. Run the following command in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require rahulalam31/laravel-abuse-ip&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Publish Configuration and Middleware
&lt;/h2&gt;

&lt;p&gt;Next, publish the package configuration and middleware files. These files allow you to customize the package’s behavior and integrate it into your application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan vendor:publish --tag=laravel-abuse-ip&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create a configuration file at&lt;code&gt;config/abuseip.php&lt;/code&gt; and a middleware file at &lt;code&gt;app/Http/Middleware/AbuseIp.php&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure the Package
&lt;/h2&gt;

&lt;p&gt;Open the configuration file &lt;code&gt;config/abuseip.php&lt;/code&gt; to customize the package settings. You can add multiple sources for fetching spam IP lists:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;return [&lt;br&gt;
    'ip_path' =&amp;gt; base_path('config/ip.json'),&lt;br&gt;
    'sources' =&amp;gt; [&lt;br&gt;
        'https://raw.githubusercontent.com/borestad/blocklist-abuseipdb/master/ips.txt',&lt;br&gt;
        'https://example.com/another-ip-list.txt',&lt;br&gt;
    ],&lt;br&gt;
    'spam_ips' =&amp;gt; function () {&lt;br&gt;
        return Cache::get('spam_ips', function () {&lt;br&gt;
            $path = config('abuseip.ip_path');&lt;br&gt;
            return file_exists($path) ? json_decode(file_get_contents($path), true) : [];&lt;br&gt;
        });&lt;br&gt;
    },&lt;br&gt;
];&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Middleware Registration
&lt;/h2&gt;

&lt;p&gt;Ensure that the middleware is registered in your application. Open app/Http/Kernel.php and add the middleware alias:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;protected $routeMiddleware = [&lt;br&gt;
    // Other middleware&lt;br&gt;
    'abuseip' =&amp;gt; \App\Http\Middleware\AbuseIp::class,&lt;br&gt;
];&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Use Middleware in Routes
&lt;/h2&gt;

&lt;p&gt;Apply the middleware to routes where you want to block spam IPs. For example, in routes/web.php:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Route::middleware(AbuseIp::class)-&amp;gt;group(function () {&lt;br&gt;
    Route::get('/dashboard', 'DashboardController@index');&lt;br&gt;
    // Other routes&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Update Spam IPs Regularly
&lt;/h2&gt;

&lt;p&gt;The package includes a console command to update the spam IP list. You can run this command manually or schedule it to run automatically.&lt;/p&gt;

&lt;p&gt;To run manually:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan abuseip:update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To schedule the command, add the following to app/Console/Kernel.php:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;protected function schedule(Schedule $schedule)&lt;br&gt;
{&lt;br&gt;
    $schedule-&amp;gt;command('abuseip:update')-&amp;gt;daily();&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Testing the Setup
&lt;/h2&gt;

&lt;p&gt;Test the middleware by simulating requests from known spam IPs. You can write feature tests to ensure that the middleware blocks the requests as expected.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;By following these steps, you can effectively block spam IPs and enhance the security and performance of your Laravel application. The &lt;a href="https://github.com/rahulalam31/Laravel-Abuse-IP" rel="noopener noreferrer"&gt;rahulalam31/laravel-abuse-ip&lt;/a&gt; package provides a simple yet powerful way to keep spammers at bay. Regularly updating your IP list and testing your middleware ensures your application remains protected against new threats.&lt;/p&gt;

&lt;p&gt;Stay secure and keep your Laravel application running smoothly by leveraging this handy package. Happy coding!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>security</category>
      <category>hackathon</category>
      <category>php</category>
    </item>
    <item>
      <title>Medium Unlimited Read</title>
      <dc:creator>Rahul Alam</dc:creator>
      <pubDate>Sat, 21 Oct 2023 11:50:51 +0000</pubDate>
      <link>https://forem.com/rahulalam31/medium-unlimited-read-1p04</link>
      <guid>https://forem.com/rahulalam31/medium-unlimited-read-1p04</guid>
      <description>&lt;p&gt;Have you ever tried to read some Medium Article and the content was locked and cannot read full. And see this...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fico06w5wvl4k5jm3r9hh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fico06w5wvl4k5jm3r9hh.png" alt="Medium Subscription Pop-up" width="800" height="580"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the solution to ignore this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;copy the article link.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;got to this &lt;a href="https://rahulalam31.github.io/unlimited-medium-hack/" rel="noopener noreferrer"&gt;URL&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9e3t0eufxl2ww0a9p91.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9e3t0eufxl2ww0a9p91.png" alt="Unlimited Medium" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;paste your link and click open link button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;you will be redirected a new tab.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By default all the design and css will be diabled. you can change it from the top menu&lt;/p&gt;

&lt;p&gt;This works for most of the article which is cached in google server.&lt;/p&gt;

&lt;p&gt;If it works for you give me a Star in my &lt;a href="https://github.com/rahulalam31/unlimited-medium-hack" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rahulalam31/unlimited-medium-hack#video-proof" rel="noopener noreferrer"&gt; Video Proof&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
