<?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
[SOLVED] simple problem (easy fix for experienced)
Moderator: General Moderators
- asi0917
- Forum Commoner
- Posts: 41
- Joined: Thu Nov 25, 2004 10:37 am
- Location: Shoreline, Washington
- Contact:
[SOLVED] simple problem (easy fix for experienced)
Last edited by asi0917 on Thu Nov 25, 2004 2:14 pm, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
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
Last edited by John Cartwright on Thu Nov 25, 2004 12:22 pm, edited 1 time in total.
DO you have Database? IT would be easier to do.
Here is how to write to the file ...
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";
}
?>
Last edited by PanK on Thu Nov 25, 2004 12:22 pm, edited 1 time in total.
- asi0917
- Forum Commoner
- Posts: 41
- Joined: Thu Nov 25, 2004 10:37 am
- Location: Shoreline, Washington
- Contact:
what does using a database intail?
crap, thats niffty, but more db info would be good
easy is music to my lazy ears
crap, thats niffty, but more db info would be good
easy is music to my lazy ears
Last edited by asi0917 on Thu Nov 25, 2004 12:34 pm, edited 1 time in total.