paymentstv Posted January 24, 2011 Share Posted January 24, 2011 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. Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/ Share on other sites More sharing options...
purencool Posted January 24, 2011 Share Posted January 24, 2011 fwrite($fp, $_SERVER['REMOTE_ADDR']. $_SESSION["sess_name"]. ' '. " $dateTime\r\n"); maybe Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/#findComment-1164254 Share on other sites More sharing options...
Psycho Posted January 24, 2011 Share Posted January 24, 2011 Or, rather than startng/exiting quoted strings multiple times: fwrite($fp, "{$_SERVER['REMOTE_ADDR']}{$_SESSION["sess_name"]} {$dateTime}\r\n"); Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/#findComment-1164257 Share on other sites More sharing options...
paymentstv Posted January 24, 2011 Author Share Posted January 24, 2011 I have tried both methods but still get the out put like this 16.17.51.41SESSION 2011/01/23 12:53:32 There is no space between ip and session. Thanks for both for trying to help. Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/#findComment-1164259 Share on other sites More sharing options...
paymentstv Posted January 24, 2011 Author Share Posted January 24, 2011 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? Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/#findComment-1164262 Share on other sites More sharing options...
PFMaBiSmAd Posted January 24, 2011 Share Posted January 24, 2011 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. Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/#findComment-1164385 Share on other sites More sharing options...
Psycho Posted January 24, 2011 Share Posted January 24, 2011 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. Link to comment https://forums.phpfreaks.com/topic/225462-how-to-print-a-white-space-to-a-text-file/#findComment-1164459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.