Writing to a server text file

This is a discussion on Writing to a server text file within the PHP General forums, part of the PHP Programming Forums category; I have this <html> <head> <title>My Program</title> </head> &...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-10-2008
kronecker@yahoo.co.uk
 
Posts: n/a
Default Writing to a server text file

I have this

<html>

<head>
<title>My Program</title>
</head>


<body>
<div>
<?

$file = ("remote.txt"); //file where data is stored
Print "Writing to $file "
$fp = fopen($file , "w"); //open the file for write
fputs($fp , "my text here"); //write the new value to the
file

fclose($fp); //close the file


?>
</div>
</body>


</html>

which runs nothing happens to the text file remote.txt - it remains
empty.
I suppose it could be its permissions - how to change these - this is
not a Unix system or at least I don't have access to the chmod
command. Or could there be something else wrong with my script? Should
the text file appear in the same directory? I created it myself and it
stays empy. Is this all I need for PHP or must I put it in a special
directory. This is an index.html file.

Thanks

K.
Reply With Quote
  #2 (permalink)  
Old 05-10-2008
AlmostBob
 
Posts: n/a
Default Re: Writing to a server text file

Try renaming index.html to index.php
That way php will know that there is something for it to do
the script will be ignored in an html file


--
Adaware http://www.lavasoft.de
spybot http://www.safer-networking.org
AVG free antivirus http://www.grisoft.com
Etrust/Vet/CA.online Antivirus scan
http://www3.ca.com/securityadvisor/virusinfo/scan.aspx
Panda online AntiVirus scan http://www.pandasoftware.com/ActiveScan/
Catalog of removal tools (1)
http://www.pandasoftware.com/download/utilities/
Catalog of removal tools (2)
http://www3.ca.com/securityadvisor/n...aspx?CID=40387
Blocking Unwanted Parasites with a Hosts file
http://mvps.org/winhelp2002/hosts.htm
links provided as a courtesy, read all instructions on the pages before use

Grateful thanks to the authors and webmasters
_


<kronecker@yahoo.co.uk> wrote in message
news:6c7f789a-62bc-4cba-9754-1ef5ac4ad0c3@a9g2000prl.googlegroups.com...
> I have this
>
> <html>
>
> <head>
> <title>My Program</title>
> </head>
>
>
> <body>
> <div>
> <?
>
> $file = ("remote.txt"); //file where data is stored
> Print "Writing to $file "
> $fp = fopen($file , "w"); //open the file for write
> fputs($fp , "my text here"); //write the new value to the
> file
>
> fclose($fp); //close the file
>
>
> ?>
> </div>
> </body>
>
>
> </html>
>
> which runs nothing happens to the text file remote.txt - it remains
> empty.
> I suppose it could be its permissions - how to change these - this is
> not a Unix system or at least I don't have access to the chmod
> command. Or could there be something else wrong with my script? Should
> the text file appear in the same directory? I created it myself and it
> stays empy. Is this all I need for PHP or must I put it in a special
> directory. This is an index.html file.
>
> Thanks
>
> K.


Reply With Quote
  #3 (permalink)  
Old 05-10-2008
AlmostBob
 
Posts: n/a
Default Re: Writing to a server text file

Mine looks like this

<?php
// Get user stats.
$getdate = date( 'd-m-Y, H:i:s' ); // Get the date & time.
$user_ip = $_SERVER['REMOTE_ADDR']; // Get the users IP.
$user_browser = $_SERVER['HTTP_USER_AGENT']; // Get the browser type.
$referer = getenv("HTTP_REFERER"); // Get the refering page.
// Look for the text file and open it for writing.
$file = "./logfiles/logfile.csv";// define the file. in a different folder,
..csv -import into excel
$fp = fopen($file, "a+");//open the text file for writing.
// Write the user stats into the text file.
fputs ($fp, "$user_ip,$getdate,$user_browser,$referer\n");
fclose($fp);// Close the text file.
?>

look for 'bbclone the web page counter on steroids' nothing to do with me,
but great if you cant access server logs on your host plan

"AlmostBob" <anonymous1@microsoft.com> wrote in message
news:dMiVj.1794$KB3.1056@edtnps91...
> Try renaming index.html to index.php
> That way php will know that there is something for it to do
> the script will be ignored in an html file
>
>
> --
> Adaware http://www.lavasoft.de
> spybot http://www.safer-networking.org
> AVG free antivirus http://www.grisoft.com
> Etrust/Vet/CA.online Antivirus scan
> http://www3.ca.com/securityadvisor/virusinfo/scan.aspx
> Panda online AntiVirus scan http://www.pandasoftware.com/ActiveScan/
> Catalog of removal tools (1)
> http://www.pandasoftware.com/download/utilities/
> Catalog of removal tools (2)
> http://www3.ca.com/securityadvisor/n...aspx?CID=40387
> Blocking Unwanted Parasites with a Hosts file
> http://mvps.org/winhelp2002/hosts.htm
> links provided as a courtesy, read all instructions on the pages before
> use
>
> Grateful thanks to the authors and webmasters
> _
>
>
> <kronecker@yahoo.co.uk> wrote in message
> news:6c7f789a-62bc-4cba-9754-1ef5ac4ad0c3@a9g2000prl.googlegroups.com...
>> I have this
>>
>> <html>
>>
>> <head>
>> <title>My Program</title>
>> </head>
>>
>>
>> <body>
>> <div>
>> <?
>>
>> $file = ("remote.txt"); //file where data is stored
>> Print "Writing to $file "
>> $fp = fopen($file , "w"); //open the file for write
>> fputs($fp , "my text here"); //write the new value to the
>> file
>>
>> fclose($fp); //close the file
>>
>>
>> ?>
>> </div>
>> </body>
>>
>>
>> </html>
>>
>> which runs nothing happens to the text file remote.txt - it remains
>> empty.
>> I suppose it could be its permissions - how to change these - this is
>> not a Unix system or at least I don't have access to the chmod
>> command. Or could there be something else wrong with my script? Should
>> the text file appear in the same directory? I created it myself and it
>> stays empy. Is this all I need for PHP or must I put it in a special
>> directory. This is an index.html file.
>>
>> Thanks
>>
>> K.

>

Reply With Quote
  #4 (permalink)  
Old 05-10-2008
kronecker@yahoo.co.uk
 
Posts: n/a
Default Re: Writing to a server text file

On May 11, 3:10 am, "AlmostBob" <anonymo...@microsoft.com> wrote:
> Mine looks like this
>
> <?php
> // Get user stats.
> $getdate = date( 'd-m-Y, H:i:s' ); // Get the date & time.
> $user_ip = $_SERVER['REMOTE_ADDR']; // Get the users IP.
> $user_browser = $_SERVER['HTTP_USER_AGENT']; // Get the browser type.
> $referer = getenv("HTTP_REFERER"); // Get the refering page.
> // Look for the text file and open it for writing.
> $file = "./logfiles/logfile.csv";// define the file. in a different folder,
> .csv -import into excel
> $fp = fopen($file, "a+");//open the text file for writing.
> // Write the user stats into the text file.
> fputs ($fp, "$user_ip,$getdate,$user_browser,$referer\n");
> fclose($fp);// Close the text file.
> ?>
>
> look for 'bbclone the web page counter on steroids' nothing to do with me,
> but great if you cant access server logs on your host plan
>
> "AlmostBob" <anonymo...@microsoft.com> wrote in message
>
> news:dMiVj.1794$KB3.1056@edtnps91...
>
> > Try renaming index.html to index.php
> > That way php will know that there is something for it to do
> > the script will be ignored in an html file

>
> > --
> > Adawarehttp://www.lavasoft.de
> > spybothttp://www.safer-networking.org
> > AVG free antivirushttp://www.grisoft.com
> > Etrust/Vet/CA.online Antivirus scan
> >http://www3.ca.com/securityadvisor/virusinfo/scan.aspx
> > Panda online AntiVirus scanhttp://www.pandasoftware.com/ActiveScan/
> > Catalog of removal tools (1)
> >http://www.pandasoftware.com/download/utilities/
> > Catalog of removal tools (2)
> >http://www3.ca.com/securityadvisor/n...aspx?CID=40387
> > Blocking Unwanted Parasites with a Hosts file
> >http://mvps.org/winhelp2002/hosts.htm
> > links provided as a courtesy, read all instructions on the pages before
> > use

>
> > Grateful thanks to the authors and webmasters
> > _

>
> > <kronec...@yahoo.co.uk> wrote in message
> >news:6c7f789a-62bc-4cba-9754-1ef5ac4ad0c3@a9g2000prl.googlegroups.com...
> >> I have this

>
> >> <html>

>
> >> <head>
> >> <title>My Program</title>
> >> </head>

>
> >> <body>
> >> <div>
> >> <?

>
> >> $file = ("remote.txt"); //file where data is stored
> >> Print "Writing to $file "
> >> $fp = fopen($file , "w"); //open the file for write
> >> fputs($fp , "my text here"); //write the new value to the
> >> file

>
> >> fclose($fp); //close the file

>
> >> ?>
> >> </div>
> >> </body>

>
> >> </html>

>
> >> which runs nothing happens to the text file remote.txt - it remains
> >> empty.
> >> I suppose it could be its permissions - how to change these - this is
> >> not a Unix system or at least I don't have access to the chmod
> >> command. Or could there be something else wrong with my script? Should
> >> the text file appear in the same directory? I created it myself and it
> >> stays empy. Is this all I need for PHP or must I put it in a special
> >> directory. This is an index.html file.

>
> >> Thanks

>
> >> K.


It just prints (the program) it out to the screen and does nothing.
Should it be ran in the cgi directory? I gave it an extension .php

k
Reply With Quote
Reply


Thread Tools
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

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



All times are GMT +1. The time now is 04:07 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0