visit.php 838 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require_once("include/config.php");
  3. require_once("include/func.php");
  4. $dsn = 'mysql:host=' . getenv("MYSQL_HOST") . ';port=' . getenv("MYSQL_PORT") . ';dbname=' . getenv("MYSQL_DATABASE");
  5. $pdo = new PDO($dsn, getenv("MYSQL_USERNAME"), getenv("MYSQL_PASSWORD"), array(
  6. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
  7. ));
  8. if(isset($_GET['q'])) { //viewing individual
  9. $short = $_GET['q'];
  10. $stmt = $pdo->query("SELECT * FROM short WHERE `short` = '$short' LIMIT 1");
  11. $result = $stmt->fetch();
  12. if($result) {
  13. $id = $result['id'];
  14. $long = $result['long'];
  15. $visits = $result['visits'] + 1;
  16. $stmt = $pdo->prepare("UPDATE short SET visits = ? WHERE id = ?");
  17. $stmt->execute( [ $visits, $id ] );
  18. header('Location: '.$long);
  19. } else {
  20. header('Location: http://s.tgxn.net/index.php?notfound');
  21. }
  22. }