Log in

View Full Version : whats wrong with this?



Demonicman
03-07-2007, 09:31 PM
i want to delete everything in the file so to make it easy for myself, i made it delete the file, then rewrite it... so why wont it work?


<?php include('mysql.php'); ?>
<?
$username = $_COOKIE['ID_my_site'];
$wordfile = "chatbox.txt";
$word = $_POST['word'];

$contentword = file_get_contents($ipfile);
$cword = explode("\r\n",$contentword);
if(!$wordfile) {die("No such file. Go <a href=\"chat.php\">back</a>.");};
$in = array_search($username, $cword);
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
while($info = mysql_fetch_array( $check )) {

if(isset($word)) {
if($username != "Demonicman"){
die('You are not an admin!');
};
/* Delete File */
unlink($wordfile);

/* Rewrite File */
$FileHandle = fopen($wordfile, 'w') or die("can't create file");
fclose($FileHandle);


/* Echo Out continue */
echo '<a href="chat.php">Continue</a>';
};
}
?>

blueflowers
03-07-2007, 09:49 PM
try this:

(it may be unsetting the var)

/* Delete File */
$newFile = $wordfile;
unlink($wordfile);

/* Rewrite File */
$FileHandle = fopen($newFile, 'w') or die("can't create file");
fclose($FileHandle);

If that doesn't work I'd be glad to take a closer look at it, just don't have time right now :)

Demonicman
03-07-2007, 10:35 PM
nope didnt work... im also having trouble with the actual chat...


<?php include('mysql.php'); ?>
<?
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$wordfile = "chatbox.txt";
$word = htmlentities($_POST['word']);

if(!$wordfile) {
die("No such file. Go <a href=\"chat.php\">back</a>.");
};

$check = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
while($info = mysql_fetch_array( $check )) {

if(isset($word)) {
/* Write message */
$handip = fopen($wordfile,"r+");
fseek($handip, 0);
fwrite($handip,"\r\n" . $username . " - " . $word ."\r\n");
fclose($handip);
/* Relocate */
header("Location: chat.php");
};
}
?>

its just overwriting what i already chatted