Computing.Net > Forums > Web Development > Newbie PHP question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Newbie PHP question

Reply to Message Icon

Name: edhardie
Date: March 17, 2005 at 11:32:06 Pacific
OS: XP/Debian linux
CPU/Ram: 300mhz 256
Comment:

Hello,
I'm trying to make an IP logger for a webpage and I found this script on the internet:

<?
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);
fclose($fp);
PRINT("Your Ip was logged.....$ip");
?>

All I want is a simple page that loggs the IP so I saved the above code into an Index.php file and uploaded it into a directory on my site. MY HOST DOES SUPPORT PHP. The directory does have write permissions. And I did CHOMD the ip.txt file to 777. It should all work right? But nothing appears in the ip.txt file, nothing atall.

What am I doing wrong, thanks
Ed



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: March 17, 2005 at 11:44:56 Pacific
Reply:

try putting these on top:

<?
error_reporting (E_ALL);
$log_file = "ip.txt";


and see if theres any error messages

---
Site of the Day


0

Response Number 2
Name: fambi
Date: March 17, 2005 at 13:03:56 Pacific
Reply:

try $_SERVER['REMOTE_ADDR']

If you're interested in SMS, visit section about sms news.


0

Response Number 3
Name: edhardie
Date: March 20, 2005 at 08:55:28 Pacific
Reply:


Warning: fopen(ip.txt): failed to open stream: Permission denied in /usr/local/apache2/htdocs/edhardie/Site2/log.php on line 5

Notice: Undefined variable: iprn in /usr/local/apache2/htdocs/edhardie/Site2/log.php on line 6

Warning: fputs(): supplied argument is not a valid stream resource in /usr/local/apache2/htdocs/edhardie/Site2/log.php on line 6

Warning: flock(): supplied argument is not a valid stream resource in /usr/local/apache2/htdocs/edhardie/Site2/log.php on line 7

Warning: fclose(): supplied argument is not a valid stream resource in /usr/local/apache2/htdocs/edhardie/Site2/log.php on line 8
your IP has been logged.....82.38.204.215

I got that when put that extra line on top.
Does it think that ip.txt is in /usr/local/apach...? because it's not.


0

Response Number 4
Name: Laler
Date: March 23, 2005 at 14:52:10 Pacific
Reply:

hiya ed,

althouh you said that you've already CHMOD ip.txt to 777, but the first notice said that the script don't have permission to write to the file...

you might want to make sure (again) that the ip.txt is chmod'd to 777 OR 666 (sometimes 777 wont work but 666 will, dont ask me why it's a little out of my logic :D -- but maybe it's related to the server settings set by the admin)

---

about the ip.txt location, nothing wrong with it... the php notice shows you the path to the file from the server's viewpoint

---

about IP logger, do you want something like this?

if so, take a look here

---

keep us posted :)

---
Site of the Day


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Newbie PHP question

easy php question www.computing.net/answers/webdevel/easy-php-question/549.html

Simple PHP Question www.computing.net/answers/webdevel/simple-php-question/2630.html

PHP Question about MYSQL interactio www.computing.net/answers/webdevel/php-question-about-mysql-interactio/1430.html