WEB Why can i post to TXT and HTML, but not PHP ?

Discussion in 'OT Technology' started by Ricky, May 2, 2008.

  1. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    im using rwrite and fopen.

    It can post to a txt and html file perfectly, but not to php.

    When i try to post to PHP i get this

     
  2. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    nothing showing up in the error log yet either
     
  3. TurkeyChicken

    TurkeyChicken New Member

    Joined:
    Jun 26, 2003
    Messages:
    42,913
    Likes Received:
    0
    Location:
    Albuquerque, NM
    what do you mean by post to php?

    Do the files have proper permissions?
     
  4. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    I dont really know the correct term since im sort of new to php.

    Basically i want it to "push" the information to another file.

    It can carry this information and "paste" it on a txt or html file, but not a php file.

    All of the files have the correct permission.
     
  5. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    the weird thing is inside the actual file the data is there, but its giving me the internal server error when i try to view it
     
  6. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    anyone :hs:
     
  7. crazybenf

    crazybenf Active Member

    Joined:
    Nov 14, 2001
    Messages:
    15,578
    Likes Received:
    3
    paste your code
     
  8. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    Code:
    <?
    // Open file for read and string modification
    $file = "lol/post.php";
    $fh = fopen($file, 'r+');
    $contents = fread($fh, filesize($file));
    $new_contents = str_replace("hello world", "hello", $contents);
    fclose($fh);
    
    // Open file to write
    $fh = fopen($file, 'r+');
    fwrite($fh, $new_contents);
    fclose($fh);
    ?>
    
    <?php
    $filename = 'lol/post.php';
    $somecontent = $_GET[search] . '<br>';
    
    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {
    
        // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence
        // that's where $somecontent will go when we fwrite() it.
        if (!$handle = fopen($filename, 'a')) {
             echo "Cannot open file ($filename)";
             exit;
        }
    
        // Write $somecontent to our opened file.
        if (fwrite($handle, $somecontent) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
        }
    
        echo "Success, wrote ($somecontent)";
    
        fclose($handle);
    
    } else {
        echo "The file $filename is not writable";
    }
    ?>
    
    
     
  9. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    i only added the extra <br> because when i was posting it to html i wanted it to atleast go on a seperate line each time.
     
  10. crazybenf

    crazybenf Active Member

    Joined:
    Nov 14, 2001
    Messages:
    15,578
    Likes Received:
    3
    make sure the permissions & owner/group are set correctly on the files and directories... thats usually what a 500 is.


    Your code works fine on my devel machine... so it's most likely a permissions issue on your end.

    chmod -R user.group ./lol/
    chmod 755 ./lol/post.php
    chmod 755 ./lol
     
  11. crazybenf

    crazybenf Active Member

    Joined:
    Nov 14, 2001
    Messages:
    15,578
    Likes Received:
    3
    [[email protected]:~]: cat lol/post.php
    lol, niggers.

    [[email protected]:~]: php -q test.php

    Success, wrote (<br>)[[email protected]:~]: cat lol/post.php
    lol, niggers.

    <br>[[email protected]:~]:
     
  12. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,766
    Likes Received:
    6
    ok i'll try that out.

    thanks
     

Share This Page