Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EricZwart's avatar

Is WHITELISTED_IPS a standard

I wanted to exclude a piece of code in a blade file using the code below. When I put WHITELISTED_IPS = in the .env file it just gave a 500 error for the complete site. Did not even place the code below yet. Is the WHITELISTED_IPS allready a standard defininition?

@unless(auth()->check() && !in_array(request()->ip(), explode(',', env('WHITELISTED_IPS', ''))))
    // Your content
@endunless
0 likes
3 replies
LaryAI's avatar
Level 58

The WHITELISTED_IPS is not a standard environment variable in Laravel or any other framework by default. It's a custom variable that you can define in your .env file to suit your application's needs.

The error you're encountering might be due to a syntax issue in your .env file or the way you're using the variable. Here are a few steps to troubleshoot and implement this correctly:

  1. Check the .env File Syntax: Ensure that your .env file is correctly formatted. The WHITELISTED_IPS variable should be defined without spaces around the = sign, like this:

    WHITELISTED_IPS=127.0.0.1,192.168.1.1
    

    Make sure there are no quotes around the IP addresses unless you specifically need them.

  2. Clear Configuration Cache: If you have cached your configuration, you need to clear it after making changes to the .env file. Run the following command:

    php artisan config:cache
    
  3. Blade Syntax: The Blade syntax you provided seems correct for checking if the user's IP is not in the whitelist. Ensure that the logic aligns with your requirements. Here's the code snippet again for clarity:

    @unless(auth()->check() && !in_array(request()->ip(), explode(',', env('WHITELISTED_IPS', ''))))
        // Your content
    @endunless
    

    This code will display the content unless the user is authenticated and their IP is in the WHITELISTED_IPS.

  4. Error Handling: If you continue to receive a 500 error, check your Laravel logs located in storage/logs/laravel.log for more detailed error messages. This can provide insight into what might be going wrong.

By following these steps, you should be able to use the WHITELISTED_IPS variable effectively in your application. If the issue persists, double-check the error logs for more specific information.

JussiMannisto's avatar
Level 50

Don't speculate, debug.

  • Read the logs to see why the 500 error happens.
  • WHITELISTED_IPS is not a standard environment variable in Laravel, but you can check if it's defined somewhere by dumping env('WHITELISTED_IPS').

Other than that, you should never use the env() helper outside the configuration files. If you run artisan config:cache or artisan optimize, env() will return null from that point on for any value. You should add an entry to a config file instead and use the config() helper.

https://laravel.com/docs/11.x/helpers#method-env

EricZwart's avatar

@JussiMannisto thanks for the reply, the logs are clear and the 500 error was not the standard Laravel Error. I forgot to mention that. And offcourse a fair point on using the environment variable in the blade file.

The problem I created is that I had the variable like this; WHITELISTED_IPS=192.168.1.1, 10.0.0.1, 127.0.0.1 The spaces where the problem. Sorry for wasting your time

Please or to participate in this conversation.