Script to append Server side variable to text file on server - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-05-2009, 10:15 AM   #1 (permalink)
Junior Member
 
Join Date: Feb 2009
Posts: 1
Default Script to append Server side variable to text file on server

I want to be able to write the address of the remote user <!--#echo var="remote_addr" --> to a text file on the server automatically when either the user clicks a button or when they visit a certain web page.

I am frankly stumped. Does anyone know of a php script that will do this?
Or any other way to do this.

Any help is greatly appreciated.

I have this so far, but I am unable to get new information to add itself to a new line and can't get both variables to work.
<?php
$filename = 'test.txt';
$ip = $_SERVER['REMOTE_ADDR'] . "\n";
$name = $_SERVER['REMOTE_USER'] . "\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, $ip, $name) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($ip) and ($name) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

Last edited by robp2175; 02-05-2009 at 12:15 PM.
robp2175 is offline   Reply With Quote
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:37 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting