Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Skip to content
- This repository
- Pull requests
- Issues
- Gist
- @dean1012
- 1
- 0
- 0
- dean1012/webgiveaway
- Code
- Issues 1
- Pull requests 0
- Wiki
- Pulse
- Graphs
- Settings
- webgiveaway/host.php
- 73c3345 on Sep 26, 2015
- @dean1012 dean1012 Optimization again...
- 1 contributor
- 77 lines (65 sloc) 1.74 KB
- <?php
- require_once 'inc/Database.php';
- require_once 'inc/SmartyT.php';
- require_once 'inc/User.php';
- require_once 'inc/SteamGame.php';
- session_start();
- // User must be logged in to see this page
- $user = User::getLoggedInUser();
- if (!$user) {
- session_write_close();
- header('Location: login.php');
- exit();
- }
- $smarty = SmartyT::getSmarty();
- $smarty->assign('user', $user);
- if (file_exists('/var/tmp/.maintenance')) {
- $smarty->display('maintenance.tpl');
- exit();
- }
- $smarty->assign('errormsg', null);
- if (isset($_POST['appid'])) {
- $appid = $_POST['appid'];
- $duration = $_POST['duration'];
- if (!is_numeric($appid)) {
- die ('FATAL ERROR: $appid not an integer');
- }
- if (!is_numeric($duration)) {
- die ('FATAL ERROR: $duration not an integer');
- } else {
- switch ($duration) {
- case 2:
- case 4:
- case 8:
- case 16:
- case 24:
- case 32:
- case 40:
- case 48:
- break;
- default:
- $smarty->assign('errormsg', 'Something went wrong, try again?');
- break;
- }
- }
- try {
- echo "TRY1";
- $game = new SteamGame($appid);
- echo "TRY2";
- $date = new DateTime();
- echo "TRY3";
- $date->add(new DateInterval("PT{$duration}H"));
- echo "TRY4"
- $expiration = $date->getTimestamp();
- echo "TRY5"
- $stmt = Database::getConnection()->prepare('INSERT INTO giveaways (appid, expiration, host) VALUES (:appid, :expiration, :host)');
- echo "TRY6"
- $stmt->execute(array(
- ':appid' => $appid,
- ':expiration' => $expiration,
- ':host' => $user->getId(),
- ));
- echo "TRY7"
- $giveawayid = Database::getConnection()->lastInsertId();
- echo "TRY8"
- session_write_close();
- echo "TRY9"
- header("Location: viewgiveaway.php?id=$giveawayid");
- echo "TRY10"
- exit();
- } catch (Exception $ex) {
- echo "EXCEPTION " . $ex->getMessage(); die();
- $smarty->assign('errormsg', 'Something went wrong, try again?');
- }
- }
- $smarty->display('host.tpl');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement