Log in

View Full Version : Help Debug this file



cursed
09-01-2006, 01:09 AM
Whats wrong with this PHP file?


<?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');
?>

blm126
09-01-2006, 02:01 AM
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.

cursed
09-01-2006, 02:04 AM
Heres the error:

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.

Twey
09-01-2006, 02:09 AM
Because you've got a floating else with no code.

cursed
09-01-2006, 02:10 AM
how can i fix this?

Twey
09-01-2006, 02:46 PM
Remove the else keyword that comes directly before function.

cursed
09-01-2006, 11:24 PM
but i need the else..

otherwise it wont work?

Twey
09-01-2006, 11:53 PM
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.
<?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');
?>

cursed
09-02-2006, 12:00 AM
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!

Twey
09-02-2006, 12:44 AM
Sorry if I offended you or bothered you in anyway. I was in a hurry and I didnt bother correcting my mistakesWhen 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. :)