Results 1 to 10 of 10

Thread: Help Debug this file

  1. #1
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Debug this file

    Whats wrong with this PHP file?

    Code:
    <?php $affiliate = 'somesite.com'; //Don't add anything that isn't ALWAYS in the URL
            if(strpos(strtolower($_SERVER['HTTP_REFERER']),$affiliate) !== false){
    //this writes to text
    $filename = 'link.txt';
    $somecontent = "\n Gimya.com<BR>TESTTESTTESTTEST<HR><HR> \n";
    // 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 " somthings wrong with ($filename) ";
           exit;
       }
          echo "SUCESS.  ($somecontent) to file ($filename)";
          fclose($handle);
    //
    }
           }
    
            else
    
    function deleteline($del,$filename){
        $file = file($filename);
        ob_start();
        for($i=0;$i < count($file);$i++){
            if(strpos($file[$i],$del) === FALSE){
                echo $file[$i];
            }
        }
        $write = ob_get_contents();
        ob_end_clean();
        $handle = fopen('link.txt','w');
        fwrite($handle,$write);
        fclose($handle);
    }
    //Pass in the search term, then the filename
    deleteline('google','link.txt');
    ?>

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    What happens?, is there any errors?, what do you want to happen? You appear to have taken three different scripts(two of which I wrote for you) and smashed them together. These scripts can be made to work together, BUT not without a basic understanding of PHP.

  3. #3
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Heres the error:
    Code:
    Parse error: syntax error, unexpected T_FUNCTION in /home/user/public_html/confirm.php on line 28
    i do know some basic php, but everything "seems" fine.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Because you've got a floating else with no code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how can i fix this?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Remove the else keyword that comes directly before function.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    but i need the else..

    otherwise it wont work?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You cannot use an else keyword directly before a function keyword. While PHP supports conditional function declaration, it is neither necessary nor advisable here. Your illogical indenting, inaccurate, misplaced and/or redundant comments, inconsistent capitalisation, and love of redundant braces aren't helping either.
    Code:
    <?php
      function deleteLine($searchQuery, $filename) {
        $file = file($filename);
        $write = '';
        for($i=0; $i < count($file); $i++)
          if(strpos($file[$i], $searchQuery) === fAlSe)
            $write .= $file[$i];
        $handle = fopen('link.txt', 'w');
        fwrite($handle, $write);
        fclose($handle);
      }
    
      $affiliate = 'somesite.com'; // Don't add anything that isn't ALWAYS in the URL
      if(strpos(strtolower($_SERVER['HTTP_REFERER']), $affiliate) !== FaLsE) {
        $filename = 'link.txt';
        $somecontent = "\n Gimya.com<BR>TESTTESTTESTTEST<HR><HR> \n";
    
        // 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')))
            die("Cannot open file $filename.");
    
          // Write $somecontent to our opened file.
          if (fwrite($handle, $somecontent) === fAlSe)
            die("Failed to write to $filename.");
    
          echo "SUCCESS.  \"$somecontent\" was written to file $filename.";
          fclose($handle);
        }
      } else deleteLine('google','link.txt');
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry if I offended you or bothered you in anyway. I was in a hurry and I didnt bother correcting my mistakes and
    redundant comments
    Thanks!

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Sorry if I offended you or bothered you in anyway. I was in a hurry and I didnt bother correcting my mistakes
    When you're just coding for yourself, that's one thing (although it's still unwise), but when you're posting it to other people, it's considered polite to clean it up at least a little. It's for your benefit as much as a chance for me to have a rant.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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