Jump to content

FOPEN-FWRITE


crashmaster

Recommended Posts

Hi there,

I need help.

How can I write $string to file (.txt)  to new line ??

 

I tried this, but it doesnt work:

 

function ban_ip($ip) {

        $path =  _path ('logs/bans.txt');

        $str = '\n'.$ip.'#'.$_SERVER["SCRIPT_NAME"];



        					@$fp = fopen ($path, 'a+');
        					@fwrite($fp, $str);
        					@fclose($fp);
        					@@chmod ($path,0777);


}

Link to comment
https://forums.phpfreaks.com/topic/99859-fopen-fwrite/
Share on other sites

IT doesnt work...

I will post you whole script here:

function _path ($path) {
    $calls = 0;
    $calls ++;
    if($calls > 15)
         return FALSE;
    if (!file_exists($path)) {
         return _path('../'.$path);
    } else {
        return $path;
    }

}



function ban_ip($ip) {

     $lol = '/pages/add/message.php';

    if ($_SERVER["SCRIPT_NAME"] != $lol) {

        $path =  _path ('logs/bans.txt');
        $str = "\n".$ip."#".$_SERVER["SCRIPT_NAME"];



        					@$fp = fopen ($path, 'a+');
                            @fwrite($fp, $str);
        					@fclose($fp);
        					@@chmod ($path,0777);
    }

}

 

bans.txt should be like this:

 

85.25.151.22#badscipt.php

85.25.151.22#badscipt.php

85.25.151.22#badscipt.php

85.25.151.22#badscipt.php

85.25.151.22#badscipt.php

...

Link to comment
https://forums.phpfreaks.com/topic/99859-fopen-fwrite/#findComment-510733
Share on other sites

try removing the "silencers" from the file write functions and see if they are giving any errors:

 

$fp = fopen ($path, 'a+');
fwrite($fp, $str);
fclose($fp);
chmod ($path,0777);

 

Also, are you viewing the contents of the file in your browser or in a text editor (vi, gedit, wordpad, etc)?

Link to comment
https://forums.phpfreaks.com/topic/99859-fopen-fwrite/#findComment-510736
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.