diff options
author | Nicolas BERNSTEIN <alexis211@gmail.com> | 2011-09-17 16:48:29 +0200 |
---|---|---|
committer | Nicolas BERNSTEIN <alexis211@gmail.com> | 2011-09-17 16:48:29 +0200 |
commit | d0060968b77c39bdf8abffb071c971c166b59edb (patch) | |
tree | 0be52e00a25bd298235a0cf916fb07496d3ab95f /lib/functions.php | |
download | Bits-d0060968b77c39bdf8abffb071c971c166b59edb.tar.gz Bits-d0060968b77c39bdf8abffb071c971c166b59edb.zip |
First commit.
Diffstat (limited to 'lib/functions.php')
-rw-r--r-- | lib/functions.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/functions.php b/lib/functions.php new file mode 100644 index 0000000..549ed3b --- /dev/null +++ b/lib/functions.php @@ -0,0 +1,52 @@ +<?php +if (!function_exists('file_put_contents')) { + function file_put_contents($filename, $data) { + $f = @fopen($filename, 'w'); + if (!$f) { + return false; + } else { + $bytes = fwrite($f, $data); + fclose($f); + return $bytes; + } + } +} + +function token_validate($message, $no_url) { + global $args, $url; + if (isset($_SESSION['token']) && $_SESSION['token'] == $args[count($args) - 1]) { + unset($_SESSION['token']); + return true; + } else { + $_SESSION['token'] = md5(time() . rand(0, 100000)); + $title = "Confirmation"; + $choice = array ( + "Yes" => $url . '-' . $_SESSION['token'], + "No" => $no_url); + require("tpl/general/choice.php"); + } +} + +function token_clear() { + global $url, $args; + if (isset($_SESSION['token']) && $_SESSION['token'] != $args[count($args) - 1]) unset($_SESSION['token']); +} + +function assert_redir($a, $u) { + if (!$a) { + header("Location: $u"); + die(); + } +} + +function assert_error($a, $e, $t = "") { + global $title; + if (!$a) { + if (!isset($title) or $t != "") { + $title = ($t == "" ? "Error" : "Error : $t"); + } + $error = $e; + require("tpl/general/empty.php"); + die(); + } +} |