PDA

View Full Version : Refresh page with a difference


Nightfire
10-08-2002, 12:11 AM
I'm working on a small script to find a page, then if the page has been found to try and delete it. I want the script to refresh up to 3 times to try and delete the page, then after the 3rd attempt if the page hasn't been deleted to show a message saying to go to the ftp and delete it manually.

This is what I have.


<?
if(file_exists("install.php")){
echo 'Trying to delete install.php now';
unlink("install.php");
?>
<script>
function retry(){
location.href='<?=$PHP_SELF?>';
}
setTimeout("retry()",4000);
</script>
<?
}else{
echo 'The file has now been deleted.';
?>
<script>
opener.document.location='index.php';
document.write("Closing window");
window.close();
</script>
<?
}
?>


If there's any typo's there, there isn't any in the original copy, I've had to type it from memory.

The way it is now, it just refreshes over and over if the file isn't deleted. So basically, instead of having someone sitting there for hours thinking it's going to do something, I just want it to stop refreshing and show an error after 3 tries. Any ideas how to do it? Is it a javascript or php thing?

Spookster
10-08-2002, 03:04 AM
Here's a quick thought. Haven't actually tried it:



$count = 0;
$filename = "install.php";

while($count<=3){
if(!file_exists($filename)){
echo "File was deleted";
break;
}
elseif($count < 3){
echo "File being deleted";
unlink($filename);
}
elseif($count == 3){
echo "File could not be deleted";
break;
}
$count++;
}

Nightfire
10-08-2002, 03:59 PM
Thanks :) I'll have a play about with it