Jump to content
xisto Community
-Sky-

Php - Ip Logger (need Help)

Recommended Posts

Warning: fopen(logs/ip_log.html) [function.fopen]: failed to open stream: Permission denied in /home/skyed211/public_html/forums/admin/iplog.php on line 10Warning: fputs(): supplied argument is not a valid stream resource in /home/skyed211/public_html/forums/admin/iplog.php on line 13Warning: fclose(): supplied argument is not a valid stream resource in /home/skyed211/public_html/forums/admin/iplog.php on line 15

Hey all.

 

OK, I'm trying to code myself an IP logger for Central-Gaming's new Admin CP page, though....I can't seem to find what's wrong. B)

 

Here is my code:

 

removed

Just a little note to other members (pointing at members who like to rip others code of work) that this logger is copyright and coded (hand-coded) by myself. I will not accept any rippers copying it. Yes, for now it's exclusively for my site, though I might release it soon.

 

On to the help I am wanting. :P

 

I am wanting to put this code into a .html page. basically if you go to "central-gaming[dot]net/admin/" it will take you to the page I made for Admins to login to the IP.Board Admin Login Panel. Basically on THAT "admins.html" page I want my php IP code to be able to log peoples IPs on that page. Anyone who has access our Admin section with unauthorized permission the IP will be logged and saved into another php/text file I coded for the logger. I just need to know how to implempt it into my .html code. I've tried using an iframe code/tag but no luck. B)

 

Thanks for your help!

Edited by -Sky-
Removed use of Note BBCode (see edit history)

Share this post


Link to post
Share on other sites

Also, have you checked the permissions on the file you are trying to write to? Make sure that you have actually set the file to be writable with permissions 0777. This will allow your script to edit the file.Also, the Notice BBCode is for use by staff members only.

Share this post


Link to post
Share on other sites

try:

$log=fopen($ipLog, 'a+');
instead of :
$log=fopen("$ipLog", "a+");
Thanks haslip. I will try it. But I want to include a iframe code into the admin page with the IPlog.php file to be able to show users their IPs.

Also, have you checked the permissions on the file you are trying to write to? Make sure that you have actually set the file to be writable with permissions 0777. This will allow your script to edit the file.
Also, the Notice BBCode is for use by staff members only.

Sorry rval. Wont use it again. :P

Share this post


Link to post
Share on other sites

As a little tip, if you're looking to include this PHP file in other files that aren't located in the same directory, you should consider absolute paths instead of relative paths like you have here:

$ipLog="logs/ip_log.html";
Also, you should be able to reduce this line:
if (preg_match("/\bhtm\b/i", $ipLog) || preg_match("/\bhtml\b/i", $ipLog)) {
to
if (preg_match("/\bhtml?\b/i", $ipLog)) {
Though i would recommend the following instead:
if (preg_match("/\.html?$/i", $ipLog)) {

Share this post


Link to post
Share on other sites

Had a minute tonight and worked on this for you.

<?php/*+--------------------------------------------------------------------------| Kel-F's PHP IP Logger| ========================================| by Kel-F| Š Š2009 Central-Gaming.net| http://central-gaming.net| ========================================| Website: http://central-gaming.net| Email: kel_flamson@hotmail.com| License: Exclusive for Central-Gaming.net.+---------------------------------------------------------------------------*/function logIP() {$ipLog="./log/ip_log.html"; // permission to write world required$ip = $_SERVER['REMOTE_ADDR'];$from = $_SERVER['HTTP_USER_AGENT']; // added Browser information$date = date ("l dS \of F Y h:i:s A"); // required escape backslash$log = fopen($ipLog, "a+");if (fputs($log, "Logged IP address: $ip - Date : $date - Using : $from\n")) {		fclose($log);		return true; // if successful write	} else {		return false; // if write not successful	}}if (logIp()) {	echo 'Logged';	} else {	echo 'Not Logged';	}?>
See the notes. Not sure if it was just the configuration i am running locally, but permisions for the txt (html) file needed to be set to world write. (0777) Also, added the User Agent to the log file. Added the if condition to return a boolean from the function.
Results are as per:
Logged IP address: 127.0.0.1 - Date : Wednesday 29th of April 2009 11:10:14 PM - Using : Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10Logged IP address: 127.0.0.1 - Date : Wednesday 29th of April 2009 11:10:16 PM - Using : Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10Logged IP address: 127.0.0.1 - Date : Wednesday 29th of April 2009 11:10:17 PM - Using : Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10
Tested working in Firefox 3.0.10 and Opera 9.64. Local XAMPP is current Apache2 / php5 similar to the Xisto.

Share this post


Link to post
Share on other sites

Thank you haslip and fusion for helping me with this php coding. B) I shall now try it again. B)

EDIT #1: I get two "Warning" errors in the php coding now.

Warning: fopen(./log/ip_log.html) [function.fopen]: failed to open stream: No such file or directory in /home/skyed211/public_html/forums/admin/iplog.php on line 20Warning: fputs(): supplied argument is not a valid stream resource in /home/skyed211/public_html/forums/admin/iplog.php on line 21Not Logged

Line "#20" code:

$log = fopen($ipLog, "a+");

Though it says "/log/log_ip.html" no such file or directory there is. And the CHMOD permissions are "0777". :P
Edited by -Sky- (see edit history)

Share this post


Link to post
Share on other sites

Not sure if it was just the configuration i am running locally, but permisions for the txt (html) file needed to be set to world write. (0777)

On Windows you don't have to do any chmodding, you just have to make sure the file isn't "read only." But on Linux and other Unix-like machines (what you are on), you have to chmod to 0777 because the web server is ran as a user other than yours.

Warning: fopen(./log/ip_log.html) [function.fopen]: failed to open stream: No such file or directory in /home/skyed211/public_html/forums/admin/iplog.php on line 20Warning: fputs(): supplied argument is not a valid stream resource in /home/skyed211/public_html/forums/admin/iplog.php on line 21Not Logged
Though it says "/log/log_ip.html" no such file or directory there is. And the CHMOD permissions are "0777". :P
Since the file iplog.php is being ran under the admin directory and since $ipLog points to a relative location, the file needs to be located at:
/home/skyed211/public_html/forums/admin/log/ip_log.html
If it is not located there, then you'll have to move it there or supply an absolute path to $ipLog. I recommend the latter, just so you can use this function in any script without worry. You can look at the global variable (array) _SERVER to figure out how to make a dynamic absolute path.

Share this post


Link to post
Share on other sites

Hi!

 

The short story: "Create log/ip_log.html and run the script again"

 

The long version:

 

Your first post had a problem of file permissions - your script was unable to create the file as the Apache account did not have permissions to do so on the directory/folder.

 

This script failed because you are trying to append to an existing file, but the file does not exist. I'd suggest you create a blank file with the same name that you are trying to write to, so the script can find and write to the specified file.

 

I suggest you do not do a chmod 0777 due to security concerns - anyone else with an account on the server would be able to modify or delete your file as you are granting them full access to your file with this command and the parameters. Either way, since achieving the functionality is of a greater concern than security at this point, do post back to let us know you were able to actually get the PHP script working.

 

Regards,

Nitin

 

 

 

Thank you haslip and fusion for helping me with this php coding. B) I shall now try it again. B)

 

EDIT #1: I get two "Warning" errors in the php coding now.

 

Warning: fopen(./log/ip_log.html) [function.fopen]: failed to open stream: No such file or directory in /home/skyed211/public_html/forums/admin/iplog.php on line 20  Warning: fputs(): supplied argument is not a valid stream resource in /home/skyed211/public_html/forums/admin/iplog.php on line 21 Not Logged

Line "#20" code:

 

$log = fopen($ipLog, "a+");

Though it says "/log/log_ip.html" no such file or directory there is. And the CHMOD permissions are "0777". :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.