New Line character & user computer name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
akkad
Forum Newbie
Posts: 14
Joined: Tue Jul 31, 2007 4:09 am

New Line character & user computer name

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

1. instead of '/r/n' use "\n"
2. 'REMOTE_ADDR' and 'REMOTE_PORT' in $_SERVER might be of interest.
akkad
Forum Newbie
Posts: 14
Joined: Tue Jul 31, 2007 4:09 am

ad

Post by akkad »

they don't contain the user computer name
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Use

Code: Select all

$_ENV['COMPUTERNAME'];
akkad
Forum Newbie
Posts: 14
Joined: Tue Jul 31, 2007 4:09 am

Post by akkad »

i tried it but its not working ?????????
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

akkad wrote:i tried it but its not working ?????????
it? The $_ENV or the gethostbyaddr thing?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If $_ENV['COMPUTERNAME'] is not set then I am not sure you will be able to get the computer name.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: New Line character & user computer name

Post by volka »

akkad wrote:2. can i write the user computer name in the file and its port.
Not the server's name.
Post Reply