Jump to content

How to print a white space to a text file?


paymentstv

Recommended Posts

Hello, I have the following code writting IP,session, and date to a text file (it works) but I want to add a white space after the IP address.

fwrite($fp, $_SERVER['REMOTE_ADDR'].  $_SESSION["sess_name"].  " $dateTime\r\n");

 

At the moment it prints like this

16.17.51.41SESSION_ID 2011/01/23 12:53:32

 

thanks in advance.

ok my bad,

 

this actually worked.

fwrite($fp, "{$_SERVER['REMOTE_ADDR']}{$_SESSION["sess_name"]} {$dateTime}\r\n");

 

just had to add a space between {$_SERVER['REMOTE_ADDR']} and {$_SESSION["sess_name"]}

Also i currently have

 

$fp = fopen('ip.txt', 'a');

where ip.txt is hosted in the same folder of server

What if i want to write to a file hosted in a different server ? http://domain.com/folder/ip.txt..etc

would

$fp = fopen('http://domain.com/folder/ip.txt', 'a');

work? tried but not writing with chmod 777

 

 

1. What would be the file permission of ip.txt?

2. Should I give same permission to the folder where ip.txt is?

 

You cannot write to a file using the http protocol.

 

The php.net fopen documentation page contains a link to a List of Supported Protocols/Wrappers that shows what you can and cannot do for each possible protocol.

 

Also i currently have

 

$fp = fopen('ip.txt', 'a');

where ip.txt is hosted in the same folder of server

What if i want to write to a file hosted in a different server ? http://domain.com/folder/ip.txt..etc

would

$fp = fopen('http://domain.com/folder/ip.txt', 'a');

work?

 

Think about the security risks of what you are asking if it were that simple to allow someone to edit files on a remote server. A couple of options are you could create a process on the external server to accept requests to update that file or you could programatically download the file via FTP, modify it, then re-upload it via FTP again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.