go.php 1018 Bytes
Newer Older
dmorley's avatar
dmorley committed
1
<?php
2 3
require_once __DIR__ . '/config.php';

dmorley's avatar
cleanup  
dmorley committed
4
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
5 6
$dbh || die('Error in connection: ' . pg_last_error());

7 8 9
$url = $_GET['url'];

if ($url) {
10 11 12 13 14 15 16 17 18 19 20
  $host = parse_url($url, PHP_URL_HOST);
  $sql    = "SELECT domain FROM pods WHERE domain LIKE '$host'";
  $result = pg_query($dbh, $sql);
  $result || die('Error in SQL query: ' . pg_last_error());
  $row = pg_fetch_all($result);
  if ($row) {
    //Add click counter +1 for $row[0]['domain'] clicks in future, seperate click table
    header('Location:' .$url);
  } else {
    die('unknown url');
  }
21
} else {
22 23 24 25 26 27
  $sql    = "SELECT secure,domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup = 1 ORDER BY RANDOM() LIMIT 1";
  $result = pg_query($dbh, $sql);
  $result || die('Error in SQL query: ' . pg_last_error());
  $row = pg_fetch_all($result);
  $scheme = $row[0]['secure'] === 'true' ? 'https://' : 'http://';
  header('Location:' . $scheme . $row[0]['domain'] . '/users/sign_up');
28
}