Name: NWS 2007-06-18 2:40 ID:PlS1wRw+
Ok I can echo "Hello World!" but the problem is that after 30 minutes it should only echo "Hello you loser!"
How do I do this?
How do I do this?
<?php
if (isset($_COOKIE['time'])) {
print (time() > ($_COOKIE['time'] + 30 * 60))
? "Hello you loser!" : "Hello World!";
}
else {
setcookie('time', time());
print "Hello World!";
}
?>
<?php
class Message {
private $message;
public function __construct($msg = '') {
$this->message = $msg;
}
public function display() {
echo $this->message;
}
}
class MessageFatal extends Message {
public function display() {
parent::display();
die;
}
}
class MessageFactory {
static public function produce($msg, $fatal = false) {
return $fatal ? new MessageFatal($msg)
: new Message($msg);
}
}
interface IGenericConfigurationProvider {
public function getValue($name);
}
class XMLConfig implements IGenericConfigurationProvider {
private $data;
public function __construct($filename = 'config.xml') {
$this->data = simplexml_load_file("config.xml");
}
public function getValue($name) {
return $this->data[$name];
}
}
$config = new XMLConfig(); // Todo: OracleDBConfig, of course.
$messages = array (
'fine' => MessageFactory::produce($config->getValue('string1'), false),
'error' => MessageFactory::produce($config->getValue('string2'), true),
);
$what = 'fine';
$messages = array (
'fine' => MessageFactory::produce($config->getValue('string1'), false),
'error' => MessageFactory::produce($config->getValue('string2'), true),
);
$what = 'fine'; // TODO: use constants.
if (isset($_COOKIE['time'])) {
if (time() < ($_COOKIE['time'] + $config->getValue('secondsInMinute') *
$config->getValue('minutesUntilChange'))) {
$what = 'error';
}
} else {
setcookie('time', time());
}
$messages[$what]->display();
?>