Get support from Xavier Media
It is currently Sun Dec 08, 2013 12:24 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: log file???
PostPosted: Wed Apr 21, 2010 3:14 pm 
Offline
Rookie
Rookie

Joined: Sun Apr 18, 2010 5:57 pm
Posts: 11
Points: 0
hi,

hope all be fine

i need to know how to create a logfile using php code?

i need to make a log file to be as a history for users enter a website


can any one help me ?

thanks in advance


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Thu Apr 22, 2010 4:22 pm 
Offline
XavierForum.com Admin
XavierForum.com Admin
Super VIP Member
Super VIP Member
User avatar

Joined: Tue Mar 15, 2005 4:37 pm
Posts: 1082
Location: Sweden
Points: 1500
This should write the text you put in as $message at the end of the log file. You need to make the file filename.txt writeable.
PHP Code:
<?
$message = "Logg message goes here \n";

$filename = fopen('filename.txt', 'a') or die();
flock($filename, 2) or die();
fputs($filename, $message);
fclose($filename);
?>

_________________
Xavier Media®
Join me at LinkedIn | Get your latest blog post in your signature you too


Report this post
Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Sat Apr 24, 2010 7:33 pm 
Offline
Rookie
Rookie

Joined: Sun Apr 18, 2010 5:57 pm
Posts: 11
Points: 0
i am afraid that i am not understanding well

do you mean i create a php file and put this code in it?

or what?


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Sun Apr 25, 2010 4:38 am 
Offline
XavierForum.com Admin
XavierForum.com Admin
Super VIP Member
Super VIP Member
User avatar

Joined: Tue Mar 15, 2005 4:37 pm
Posts: 1082
Location: Sweden
Points: 1500
Yes, you create a PHP file and put this code in. You then need to call this file for every PHP file where you want the user actions to be logged. You also need to adjust the message to what you want to log (for example IP address, file name etc).

_________________
Xavier Media®
Join me at LinkedIn | Get your latest blog post in your signature you too


Report this post
Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Tue Apr 27, 2010 8:10 pm 
Offline
Rookie
Rookie

Joined: Sun Apr 18, 2010 5:57 pm
Posts: 11
Points: 0
bylla wrote:
Yes, you create a PHP file and put this code in. You then need to call this file for every PHP file where you want the user actions to be logged. You also need to adjust the message to what you want to log (for example IP address, file name etc).



thanks alot , i got it.

but i need to ask

what is that mean
Quote:
'a') or die()

and
Quote:
2) or die();


thanks in advance


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Tue Apr 27, 2010 8:21 pm 
Offline
Rookie
Rookie

Joined: Sun Apr 18, 2010 5:57 pm
Posts: 11
Points: 0
another question plz

how can i make my log file be saved in my database automatically?


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Thu Apr 29, 2010 5:23 pm 
Offline
XavierForum.com Admin
XavierForum.com Admin
Super VIP Member
Super VIP Member
User avatar

Joined: Tue Mar 15, 2005 4:37 pm
Posts: 1082
Location: Sweden
Points: 1500
PHP Code:
die();
means that the code will stop if it fails. In the code below die() will print an error message if it fails (see the code).

To write your log file to a database instead you just add something like this instead of writing to a file:
PHP Code:
<?
$mySQL_host = "hostname"; // Usually localhost, but may also be a hostname
$mySQL_user = "database user name";
$mySQL_pwd = "your password";

$DataBase = "the name of your database";

$message = "The log information you want to save in your database";

$mySQL_ID = mysql_connect($mySQL_host, $mySQL_user, $mySQL_pwd) or die ('I cannot connect to the database because: ' . mysql_error(). '');

$mySQLBOOL = mysql_select_db($DataBase,$mySQL_ID) or die ('Database problems because: ' . mysql_error(). '');

mysql_query("INSERT INTO TableName VALUES('$message')");

?>
Now you need to create a table in your database called TableName (change the name to something useful) and use the above code to log your information.

_________________
Xavier Media®
Join me at LinkedIn | Get your latest blog post in your signature you too


Report this post
Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Thu Apr 29, 2010 9:05 pm 
Offline
Rookie
Rookie

Joined: Sun Apr 18, 2010 5:57 pm
Posts: 11
Points: 0
ohh


i have put the code you posted and did what you instructed for but no result and no errors also.

now i will show you what i have done exactly in this part

and could you help me is this criteria true or not?

here is my way:
1- make a log.php file
2- make a table in the data base and its variables are:

ip, agent, ref, query, date

then this is the code:

Code:
<?php

   $ip = $_SERVER['REMOTE_ADDR']; //Get there ip address.
   $agent = $_SERVER['HTTP_USER_AGENT']; //Get there user agent, Firefox etc, and some other info about it.
   $ref = $_SERVER['HTTP_REFERER']; // Referer, how they got to your website, who linked them, where they clicked that link.
   $uri = $_SERVER['REQUEST_URI'];    //The URI which was given in order to access this page; for instance, '/index.html'.                  
   $date = date("H:i dS F"); //Get the date and time.
   
    //To save the logging data in the Data base

$mySQL_host = "localhost";
$mySQL_user = "my user name";
$mySQL_pwd = "my pwd";
$DataBase = "my db name";

$message = "IP: " . $ip . "USERAGENT: " . $agent . " REFERRER: " . $ref . " SEARCHSTRING: " . $query . " DATE: " . $date;

$mySQL_ID = mysql_connect($mySQL_host, $mySQL_user, $mySQL_pwd) or die ('I cannot connect to the database because: ' . mysql_error(). '');

$mySQLBOOL = mysql_select_db($DataBase,$mySQL_ID) or die ('Database problems because: ' . mysql_error(). '');

mysql_query("INSERT INTO tablename VALUES('$message')");


?>


then i reffered to this log.php file in the logout.php file

but there is nothing saved in the database :cry:
is this true or what?

thanks alot


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Sun May 02, 2010 7:14 am 
Offline
XavierForum.com Admin
XavierForum.com Admin
Super VIP Member
Super VIP Member
User avatar

Joined: Tue Mar 15, 2005 4:37 pm
Posts: 1082
Location: Sweden
Points: 1500
You need to input the data into the table in the same way you've created the table. If you for example just input message then you need to have just one text variable called text. If you do as you said in point 2 you need to input the data into the table like this:
PHP Code:
mysql_query("INSERT INTO tablename VALUES('$ip','$agent','$ref','$query','$date')");

_________________
Xavier Media®
Join me at LinkedIn | Get your latest blog post in your signature you too


Report this post
Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: log file???
PostPosted: Mon May 03, 2010 11:22 pm 
Offline
Rookie
Rookie

Joined: Sun Apr 18, 2010 5:57 pm
Posts: 11
Points: 0
thanks alot

i tried and did it

thanks again


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]