bu işine yarar gün dönümünü denemedim
<?php
class sozler {
public function __construct($action='read'){
if(!file_exists('sozler.lock')){
$this->write();
}
switch($action){
case 'read':
$this->read();
break;
case 'write':
$this->write();
break;
case 'select':
$this->select();
break;
default:
$this->read();
}
}
public function read(){
$handle = fopen('sozler.lock', "r");
$data = unserialize(fread($handle, filesize('sozler.lock')));
fclose($handle);
if($data['tarih']=!date('Y-m-d')){
$this->write();
$this->read();
} else {
echo $data['soz'];
}
return false;
}
public function write(){
$write = array();
$write['tarih'] = date('Y-m-d');
$write['soz'] = $this->select();
if(file_put_contents('sozler.lock',serialize($write))){
return true;
}
return false;
}
public function select(){
$dosya = fopen("sozler.txt","r");
while($satir = fgets($dosya,1024))
$sozler[] = $satir;
fclose($dosya);
return $sozler[rand(0,count($sozler)-1)];
}
}
new sozler();
?>
öncelikle teşekkürler kod Warning: file_put_contents(sozler.lock): failed to open stream: Permission denied in hata verdi.
benim kod çalısıyor fakat sadace 24 saatte bir söz yayınlamasını saglamak istiyorum önemli olan gün dönümü