go.php 1 KB
Newer Older
dmorley's avatar
dmorley committed
1
<?php
2 3 4 5

// Other parameters.
$_url = $_GET['url'] ?? '';

6 7
require_once __DIR__ . '/config.php';

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

11 12 13 14
if ($_url) {
  $host   = parse_url($_url, PHP_URL_HOST);
  $sql    = 'SELECT domain FROM pods WHERE domain LIKE $1';
  $result = pg_query_params($dbh, $sql, [$host]);
15
  $result || die('Error in SQL query: ' . pg_last_error());
16

17
  $row = pg_fetch_all($result);
18 19 20 21
  $row || die('unknown url');

  //Add click counter +1 for $row[0]['domain'] clicks in future, separate click table
  header('Location:' . $_url);
22
} else {
dmorley's avatar
dmorley committed
23
  $sql    = 'SELECT secure,domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup ORDER BY RANDOM() LIMIT 1';
24 25
  $result = pg_query($dbh, $sql);
  $result || die('Error in SQL query: ' . pg_last_error());
26 27

  $row    = pg_fetch_all($result);
dmorley's avatar
dmorley committed
28
  $scheme = $row[0]['secure'] ? 'https://' : 'http://';
29
  header('Location:' . $scheme . $row[0]['domain'] . '/users/sign_up');
30
}