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. Quote Link to comment 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 Quote Link to comment 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"); Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.