Welcome Guest, Not a member yet? Register   Sign In
File helper... not helping
#1

[eluser]richzilla[/eluser]
Hi all, im having a little bit of a problem getting to grips with the file helper. Im trying to get it to write to a log file so i can see when users have logged into my application, made changes etc etc. However, although i seem to have loaded everything correctly, it is making no effort to write to the file. Ive checked file an folder permissions all the way back to my root folder and there all good, but when i use the get_filenames method, it cant find it either.

My code is:

i set the data to be written here:

Code:
$this->write_log(unix_to_human(now()).': USER: '.$this->session->userdata('userid').' Logged In');

and the method being called

Code:
function write_log($data)
    {
        write_file(base_url().'assets/log/main_log.txt',$data);
    }

i appreciate i could be missing something simple, so if anyone can point me in the correct direction, i would appreciate it.

Cheers
#2

[eluser]Phil Sturgeon[/eluser]
You cannot write to a URL. Instead you must write to a path.

Code:
function write_log($data)
    {
        write_file(APPPATH.'assets/log/main_log.txt',$data);
    }
#3

[eluser]richzilla[/eluser]
Fantastic, worked a treat. How would i get it to add a new line after every entry? at present its just stacking everything up together. Ive tried adding '/n' to the end of the $data variable but still no luck.

Cheers
#4

[eluser]bretticus[/eluser]
[quote author="ricardino" date="1254774320"]How would i get it to add a new line after every entry? at present its just stacking everything up together. Ive tried adding '/n' to the end of the $data variable but still no luck.[/quote]
Code:
$string = "My new line\n";
write_file('./path/to/file.php', $string, 'a');
#5

[eluser]BrianDHall[/eluser]
Addition to bretticus's tip - be sure to use double-quoted strings! It won't work if you use single quotes.
#6

[eluser]John_Betong[/eluser]
 
>>> i appreciate i could be missing something simple, so if anyone can point me in the correct direction, i would appreciate it.
 
For a very similar problem I have just used CI's Session Class and "Saving Session Data to a Database".
 
Many thanks to a clear and descriptive previous post from BrianDHall - standing on the shoulders' of giants springs to mind Smile
 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB