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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.