Page 1 of 1

New Line character & user computer name

Posted: Thu Aug 09, 2007 4:33 am
by akkad
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi every body, in this code i am trying to write to file on linux server :

Code: Select all

$c=$_SERVER['HTTP_HOST'];
echo $_SERVER['REMOTE_PORT'];

$ip_add=$c;

$today=date("d-M-y");
$date = date("Y-M-d H:i:s");
 
$logfile = $today."_log.txt"; 
$dir = 'log';
$saveLocation=$dir . '/' . $logfile;
$logMessage=$ip_add;
if(!is_dir($dir))
{
   mkdir($dir,"0755");
}

if (!$handle = fopen($saveLocation, "a"))
{
     //ERROR, DO SOMETHING
     #echo "can't create the file";
     exit;
}
else
{
     if(fwrite($handle,'Date: '.$date. ' IP: '. $logMessage.'  '.'/r/n')===FALSE) 
     {
          //ERROR, DO SOMETHING
         # echo " can't write to the file ";
          exit;
     }
  
     fclose($handle);
}
1. how to go to new line each time we are writting in the file (/r/n it is not working, it is writing it in the file as /r/n) like this:
Date: 2007-Aug-09 09:12:36 IP: 10.6.0.15 /r/n
2. can i write the user computer name in the file and its port.
coz i want to create a log file for each user loggin into the system


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 09, 2007 4:49 am
by volka
1. instead of '/r/n' use "\n"
2. 'REMOTE_ADDR' and 'REMOTE_PORT' in $_SERVER might be of interest.

ad

Posted: Thu Aug 09, 2007 6:08 am
by akkad
they don't contain the user computer name

Posted: Thu Aug 09, 2007 6:14 am
by volka
But that's all you get.
You can try to get a name associated with the address via gethostbyaddr. This might or might not work.

Posted: Thu Aug 09, 2007 6:15 am
by dude81
Use

Code: Select all

$_ENV['COMPUTERNAME'];

Posted: Thu Aug 09, 2007 9:12 am
by akkad
i tried it but its not working ?????????

Posted: Thu Aug 09, 2007 9:39 am
by volka
akkad wrote:i tried it but its not working ?????????
it? The $_ENV or the gethostbyaddr thing?

Posted: Thu Aug 09, 2007 1:13 pm
by RobertGonzalez
If $_ENV['COMPUTERNAME'] is not set then I am not sure you will be able to get the computer name.

Posted: Thu Aug 09, 2007 11:57 pm
by dude81
what should we do to enable in PHP to get $_ENV Global Array, between I think gethostbyaddr would give the computer name that is configured in Apache, but not actual computername

Re: New Line character & user computer name

Posted: Fri Aug 10, 2007 5:39 am
by volka
akkad wrote:2. can i write the user computer name in the file and its port.
Not the server's name.