Page 1 of 1
[SOLVED] simple problem (easy fix for experienced)
Posted: Thu Nov 25, 2004 12:17 pm
by asi0917
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
?>
i want to track the IPs that view my site,
how do i save $ip to a file like a .dat or something?
_________________
help=goodness
Posted: Thu Nov 25, 2004 12:21 pm
by John Cartwright
you are must better off using a database. But if you insist on writing to a text file you can do either of the following
1) search these forums, it has been discussed several times.
[devnet]+writing +text +file[/devnet]
2) go to [php_man]fopen[/php_man], [php_man]fwrite[/php_man], [php_man]fclose[/php_man] to write to the file and [php_man]file_get_contents[/php_man] to read the file
Posted: Thu Nov 25, 2004 12:22 pm
by PanK
DO you have Database? IT would be easier to do.
Here is how to write to the file ...
Code: Select all
<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
Posted: Thu Nov 25, 2004 12:22 pm
by asi0917
what does using a database intail?
crap, thats niffty, but more db info would be good
easy is music to my lazy ears
Posted: Thu Nov 25, 2004 8:22 pm
by josh
you need a host that uses mysql