• Resolved ld2002

    (@ld2002)


    Hey there,

    first of all, thanks for the plugin. It works very well and i like the easy way, to restrict the access off the Website.

    The server, the website is running on is standing in my home-network, and i want, that users, which have the same public ip adress like the server can access the website without any login. In the context, all user, which are using the internet at home.

    I created following code in the wp-config. php:

    // Rufe den checkip.dyndns.org-Dienst auf und speichere die Rückgabewerte in einer Variablen
    $ip_address = file_get_contents('http://checkip.dyndns.org');
    
    // Entferne alle nicht-numerischen Zeichen aus den Rückgabewerten, um nur die IP-Adresse zu erhalten
    $ip_address = preg_replace('/[^0-9.]/', '', $ip_address);
    
    // Speichere die IP-Adresse in einer Variablen
    $server_ip = $ip_address;
    
    // Öffnet das Dokument mit schreiben
    $file = fopen("ipneu.txt", "w");
    
    // Schreibt die IP-Adresse in das Dokument 
    fwrite($file, $server_ip . "\n");
    
    fclose($file);
    
    // Fügt die IP-Adresse zu den "erlaubten" hinzu. 
    Restricted_Site_Access::add_ips( array( 'five' => $server_ip) );

    When i run this code, i get a http 500 failure. When i comment out the “Restricted_Site_Access” my code works fine and the ip-adress is written into the document. But i have to login, also when i use the same public IP-Adress. Logical. I write the ip to the document, that i can check, that my code works well. When everything will work, i will remove this part of the code.

    Sorry if there are stupid errors, I’m just starting to deal with php.

    Can you help me out with that?

    Thanks!

    Greetings,

    Luca

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Siddharth Thevaril

    (@nomnom99)

    Hi @ld2002

    wp-config.php loads before the Restricted Site Access plugin.

    This is the reason why running Restricted_Site_Access::add_ips( array( 'five' => $server_ip) ); inside wp-config.php throws an error.

    I would suggest creating a small plugin and running this code on the plugins_loaded hook.

    Or, if you’re not comfortable with creating a plugin, then you can use the Code Snippets Pro plugin and achieve the same result.

    Let us know if that helps.

    Cheers!

    • This reply was modified 1 year, 6 months ago by Siddharth Thevaril. Reason: improve grammar
    Thread Starter ld2002

    (@ld2002)

    Hey @nomnom99

    Thank you very much for your help. I created a small plugin and uploaded it to the website and it works fine. The IP-Adress is also shown on the settings-page. Everything i want works now.

    Here is my plugin:

    <?php
    /**
     * Plugin Name: Add IP to RSA
     */
    
    add_action( 'plugins_loaded', 'load_ip_adress' );
    
    function load_ip_adress()
    {
    $ip_address = file_get_contents('http://checkip.dyndns.org');
    $ip_address = preg_replace('/[^0-9.]/', '', $ip_address);
    $server_ip = $ip_address;
    Restricted_Site_Access::add_ips( array( 'five' => $server_ip) );
    }
    ?>

    Greetings

    Luca

    Plugin Contributor Siddharth Thevaril

    (@nomnom99)

    Awesome! I’m glad that worked!

    I will close this ticket and mark it as resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add IP address via variable.’ is closed to new replies.