| View previous topic :: View next topic |
| Author |
Message |
compactwater I post too much
Reputation: 8
Joined: 02 Aug 2006 Posts: 3923
|
Posted: Thu Nov 22, 2007 8:14 pm Post subject: php logger |
|
|
| Code: | <?php
if (isset($_REQUEST["username"])) {
$logname = "logs/user_" . $_REQUEST["username"] . "_" . date("Ymd") . "_.log";
$handle = fopen($logname, 'a');
if (!$_REQUEST["text"] == "") {
$toput = $_REQUEST["text"] . "
"; } else {
$toput = $_REQUEST["l0"] . "
" . $_REQUEST["l1"] . "
" . $_REQUEST["l2"] . "
" . $_REQUEST["l3"] . "
" . $_REQUEST["l4"] . "
" . $_REQUEST["l5"] . "
" . $_REQUEST["l6"] . "
" . $_REQUEST["l7"] . "
" . $_REQUEST["l8"] . "
" . $_REQUEST["l9"]; }
if (fwrite($handle, $toput) === FALSE) {
echo "1";
fclose($handle);
} else {
echo "0";
fclose($handle); }
}
?> |
This is a logger. It will log things. The original idea was to be used to (key)log a person- I'll leave that part to your imagination.
You will need PHP, and full access to the 'logs' directory (you can change that). This will return 1 if there was an error, or 0 if everything went fine.
Usage:
/log.php?username=test&text=Hello world!
Or, to log multiple lines:
/log.php?username=test&l0=Hello&l1=world!&l5=How are you doing?&l9=I'm fine!
Example log file:
user_test_20071122_.log
inside:
Example log 2:
inside:
| Code: | Hello
world!
How are you doing?
I'm fine! |
This can also be used with a form.
| Code: | <form action="log.php" method="POST">
Username:<br />
<input type="text" name="username"><br />
Message:<br />
<textarea NAME="text" cols="40" rows="6"></textarea><br />
<input type="submit" value="Log it">
</form> |
It will look like this...
When using only one line, you can force it to start on another line by adding "%0D%0A" to the url.
Exmaple:
/log.php?username=morethenone&text=How are you?%0D%0AI'm fine.
That will give you:
| Code: | How are you?
I'm fine. |
If you want to see what was recorded, change:
| Code: | if (fwrite($handle, $toput) === FALSE) {
echo "1";
fclose($handle);
} else {
echo "0";
fclose($handle); }
} |
to
| Code: | if (fwrite($handle, $toput) === FALSE) {
echo "1";
fclose($handle);
} else {
echo "0<br/>";
echo $toput;
fclose($handle); }
} |
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Thu Nov 22, 2007 8:23 pm Post subject: |
|
|
You should use a database for this.
_________________
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Thu Nov 22, 2007 9:02 pm Post subject: |
|
|
| Compactwater. Cross Site Scripting?
|
|
| Back to top |
|
 |
compactwater I post too much
Reputation: 8
Joined: 02 Aug 2006 Posts: 3923
|
Posted: Thu Nov 22, 2007 9:05 pm Post subject: |
|
|
| dnsi0 wrote: | | Compactwater. Cross Site Scripting? | To keep anyone from doing that, use &_SERVER["HTTP_REFERER"], if it's not from your site (or wherever you want it to come from) then deny access.
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Thu Nov 22, 2007 9:06 pm Post subject: |
|
|
| compactwater wrote: | | dnsi0 wrote: | | Compactwater. Cross Site Scripting? | To keep anyone from doing that, use &_SERVER["HTTP_REFERER"], if it's not from your site (or wherever you want it to come from) then deny access. |
Extremely insecure. Referer(sic) headers are EASILY and OFTEN spoofed as part of penetration testing. Do not do this.
_________________
|
|
| Back to top |
|
 |
compactwater I post too much
Reputation: 8
Joined: 02 Aug 2006 Posts: 3923
|
Posted: Thu Nov 22, 2007 9:07 pm Post subject: |
|
|
Then maybe doing it in .htaccess will suit your needs?
Ahh, well this was intended for personal use.
|
|
| Back to top |
|
 |
|