Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problems writing to file

    PHP Code:
    <?php
    $thefile 
    fopen("ipgrabber.txt");
    fwrite($thefilegetenv("REMOTE_ADDR") . "\n");
    fclose($thefile);
    echo 
    $_SERVER['REMOTE_ADDR']; 
    echo 
    " wrote to $thefile";
    ?>
    Everything looks right to me, but I get this error
    Code:
    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 4
    Thanks for any and all help!!
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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 ./
    Code:
    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
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    / is the root directory, ../ means the previous directory, ./ means this directory in a seperate folder, similar to just plain / hope all that helps....


    Jason

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Jun 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #9
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to set your permissions.... chmod 777 the file.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •