Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

PHP error


t0xikc0mputer's Avatar
Member
0 0

Hello all,

First off, before anything pertaining to this topic, I do, in fact know that there was an article posted by techb with the exact same title. I do not care, it is a PHP error, and so that shall be the title.

Now for the real problem:

I was dickin around with php and was experimenting with the

markup$ip = $_SERVER['REMOTE_ADDR'];

thing. I put some code up on my website

$date = date("d-m-y / H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$file = fopen("logs.txt", "a+");
$text = $date."<br />".$ip."<br />---<br /><br />";
fwrite($file, $text);
fclose($file);
?>```

to try and (as a test) track the ips of the visitors. (Just for experimental, and educational purposes of course) ;) I expected it to work, because that syntax, is (as far as I know) to the letter from w3schools. Now I know they don't have the best PHP tutorials in the world, but I at least expect their syntax to be correct. The problem is that it came up with the below error:

> Warning: fopen(logs.txt) [function.fopen]: failed to open stream: Permission denied in ****************

and then

> 
Warning: fwrite(): supplied argument is not a valid stream resource in ****************


Warning: fclose(): supplied argument is not a valid stream resource in ****************

Now, as far as I know, the second two errors were caused by the first error, and I believe that if the first one were fixed the other two would go away. Also, this script was supposed to create a 'logs.txt' file, as there was no existing one. (although I am pretty sure that pre-creating one would not solve the problem)

I use 000webhost.com, any idea why this might happen, and how to fix it?

Thanks,

t0xik

Also, for ynori7's sake, I did google it to see what I could find out, but nothing helpful came up.

ghost's Avatar
0 0

t0xikc0mputer wrote: Now, as far as I know, the second two errors were caused by the first error No, they came to be because you supplied $fopen instead of $file.


t0xikc0mputer's Avatar
Member
0 0

COM wrote: [quote]t0xikc0mputer wrote: Now, as far as I know, the second two errors were caused by the first error No, they came to be because you supplied $fopen instead of $file.[/quote]

Fixed it and it still comes up with same error.


ghost's Avatar
0 0

t0xikc0mputer wrote: fixed and it still comes up with same error. Of course it does, you never got a valid stream resource since you couldn't open the file for writing and didn't have any error checking to not try to write to it in such a case. Just set the permissions of whatever directory you're in so that you can write to it. And also, if you're going to write that much code for something like that, at least throw some error checking in the script.


t0xikc0mputer's Avatar
Member
0 0

COM wrote: [quote]t0xikc0mputer wrote: fixed and it still comes up with same error. Of course it does, you never got a valid stream resource since you couldn't open the file for writing and didn't have any error checking to not try to write to it in such a case. Just set the permissions of whatever directory you're in so that you can write to it. And also, if you're going to write that much code for something like that, at least throw some error checking in the script.[/quote]

I don't really need error checking, I am just fooling around, but if I was using this for real, I would. The errors are all gone, as I have modded the public directory to 777, but when I check the logs.txt file, it appears blank.

EDIT: Now, I have tried to mod the logs.txt file itself to 777, but it says > Could not change perms: operation not permitted