Write file on php

前端 未结 3 1200
生来不讨喜
生来不讨喜 2021-01-25 18:20

I want to keep ips from visitors and place them on a file.
I tried fwrite() function but I think it is rewrite on the previus ip on file.

Example.

ip.txt is

相关标签:
3条回答
  • 2021-01-25 18:49

    The 'advantage' of the database version is that no one can view the data. If neccesary, you can avoid access to the file by using a .htaccess file:

    For apache 2.2

    # Protect log.txt
    <Files ./inscription/log.txt>
    Order Allow,Deny
    Deny from all
    </Files>
    

    For apache 2.4

    # Protect log.txt
    <Files ./inscription/log.txt>
    Require all denied
    </Files>
    
    0 讨论(0)
  • 2021-01-25 19:07
    <?php
    $file = fopen("ip.txt","a");
    $ip=$_SERVER['REMOTE_ADDR'];
    echo fwrite($file,$ip);
    fclose($file);
    ?> 
    

    Look at the manual

    Check what the 2nd parameter means.

    Youve chosen w mode which is an overrwrite mode. Try a mode instead (append)

    0 讨论(0)
  • 2021-01-25 19:13

    Change "w" to "a"

    W means write (over), a means append.

    0 讨论(0)
提交回复
热议问题