Hi,

I wondered if it's possible to make PHP save some info to another file on the same server.

An example:

index.php should check if the visitor's IP is allowed to open the page, if not, the IP should be added to banned_ips.php

index.php would look something like this

// Log IP Address as $ip
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);

// Load allowed IP's
include('allowed_ips.php');

if ($ip != $allowed_ip){ echo "Your IP is not reckognized as an allowed IP, access denied."; exit; }

With that access denied message I would like to have the IP logged to banned_ips.php. Any way to do this ? Thanks.

    yes...you'll need the permissions on your server set so that the webserver can write to the folder in question, you'll need to know the full path to your log file, and you might also want to check out serialize()...this command can take any complex data structure (arrays, objects, etc) and make it so you can store it in a database, in a file, etc. also check out these file functions in the documentation:

    fopen
    fread
    fwrite
    fclose

    they should have cross references and examples to a variety of other useful functions here:

    http://www.php.net/manual/en/function.fread.php

      Write a Reply...