...

View Full Version : Problems writing to file



SDP2006
10-06-2003, 10:12 PM
<?php
$thefile = fopen("ipgrabber.txt");
fwrite($thefile, getenv("REMOTE_ADDR") . "\n");
fclose($thefile);
echo $_SERVER['REMOTE_ADDR'];
echo " wrote to $thefile";
?>
Everything looks right to me, but I get this error


Warning: Wrong parameter count for fopen() in c:\ibserver\www\ipgrabme.php on line 2

Warning: fwrite(): supplied argument is not a valid File-Handle resource in c:\ibserver\www\ipgrabme.php on line 3

Warning: fclose(): supplied argument is not a valid File-Handle resource in c:\ibserver\www\ipgrabme.php on line 4Thanks for any and all help!!

Socraties
10-06-2003, 10:26 PM
when using fopen() you need to specify what you are opening the file for read, write, append ... This link may help.

http://us2.php.net/manual/en/function.fopen.php

this should work :

$thefile = fopen("ipgrabber.txt", "w+");
or
$thefile = fopen("ipgrabber.txt", "a+");

This should take care of the rest of the errors.

SDP2006
10-06-2003, 11:38 PM
Okay. That works!!

Now, I'm including it in my index page so that the users ip and user agent is being wrote to the file by this
<?php
$file = "./php-bin/ipgrabme.php";
include($file);
?>but I then get this error. I am accessing this in another folder, so would it be ../ or ./ that would be causing these errors. I get different errors using ../ and ./

Warning: Unable to access ./php-bin/ipgrabme.php in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/categories.php on line 19

Warning: Failed opening './php-bin/ipgrabme.php' for inclusion (include_path='.:/usr/local/psa/apache/lib/php') in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/categories.php on line 19

Jason
10-07-2003, 01:56 AM
/ is the root directory, ../ means the previous directory, ./ means this directory in a seperate folder, similar to just plain / hope all that helps....


Jason

SDP2006
10-07-2003, 03:41 AM
This is the error I get using ../php-bin/ipgrabme.php
http://www.net-riches.com/includes/test.php

This is the error I get using ./php-bin/ipgrabme.php
http://www.net-riches.com/includes/test1.php

The code works fine until I want to include it!

Socraties
10-07-2003, 10:19 PM
Well if it is in another folder where is the relationship to that folder from the directory your index page is in?

lets say this is the directory where your index page is:

/var/www/html/php/index.php

and the file you want to include is in this directory:

/var/www/html/php/include_files

then your include statement in your index.php page should look like this:

include("include_files/filename"); or include("/include_files/filename") notice there is not . in front of the / for this one.

I have found that sometimes you need to play with your slashes and dots, i hve found that different servers and configurations can determine how it translates that. I have also found the servers mood to be a determining factor as well :) hope that helped you some.

Socraties
10-10-2003, 08:58 PM
After noodling around on your site you should be able to put this in and have it work.


<?php
$file = "../php-bin/ipgrabme.php";
include($file);
?>

the php-bin directory is in a directory below your include direcotry. The reason you are getting a permissions error is more than likely you are trying to go to a directory that does not exist and your server is not liking it.... The above code should fix your problems.

SDP2006
10-11-2003, 04:46 AM
Gee, I wish --

Warning: fopen("ipgrabber.txt", "a+") - Permission denied in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/php-bin/ipgrabme.php on line 2

Warning: fwrite(): supplied argument is not a valid File-Handle resource in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/php-bin/ipgrabme.php on line 3

Warning: fclose(): supplied argument is not a valid File-Handle resource in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/php-bin/ipgrabme.php on line 4

cv98
10-16-2003, 02:12 AM
You need to set your permissions.... chmod 777 the file.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum