MyBB Community Forums

Full Version: Writing to a text file with PHP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am having an issue with a PHP code. I want to set it so that when somebody submits a form, their IP address is written to a text file for later use.

This works, but is not what I want
$ip = $_SERVER['REMOTE_ADDR'];
$fh = fopen("iplog.txt", "a");
fwrite($fh, $ip);
fclose($fh);
if (isset($_POST['submit'])) {

This is what I want, but it doesn't work
if (isset($_POST['submit'])) {
$ip = $_SERVER['REMOTE_ADDR'];
$fh = fopen("iplog.txt", "a");
fwrite($fh, $ip);
fclose($fh);

Please help. Thanks Smile
Is your submit button named "submit"?

As in:
<input type="submit" name="submit" />
I believe so he wants this so that I cant fill in the form twice ^^.
(2009-11-23, 03:00 AM)DougSD Wrote: [ -> ]Is your submit button named "submit"?

As in:
<input type="submit" name="submit" />

Yes, it is. The rest of the code works, just that part. Even this code is working (lower in the code):

$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);


(2009-11-23, 03:02 AM)Zomaian Wrote: [ -> ]I believe so he wants this so that I cant fill in the form twice ^^.

Not just you, everyone Smile

----------------------

I know it's something either to do with iplog.txt (which IS CHMOD 777) or the code itself that I posted in the first post.