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

// Other parameters.
4
$_domain = $_GET['domain'] ?? '';
5

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

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

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

16
  $row = pg_fetch_all($result);
17
  $row || die('unknown domain');
18

dmorley's avatar
dmorley committed
19
  $sql    = 'INSERT INTO clicks (domain, manualclick) VALUES ($1, $2)';
20
  $result = pg_query_params($dbh, $sql, [$_domain, '1']);
dmorley's avatar
dmorley committed
21 22
  $result || die('Error in SQL query: ' . pg_last_error());
  
23
  header('Location: https://' . $_domain);
24
} else {
dmorley's avatar
dmorley committed
25
  $sql    = 'SELECT domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup ORDER BY RANDOM() LIMIT 1';
26 27
  $result = pg_query($dbh, $sql);
  $result || die('Error in SQL query: ' . pg_last_error());
28 29

  $row    = pg_fetch_all($result);
dmorley's avatar
dmorley committed
30 31 32 33 34
  
  $sql    = 'INSERT INTO clicks (domain, autoclick) VALUES ($1, $2)';
  $result = pg_query_params($dbh, $sql, [$row[0]['domain'], '1']);
  $result || die('Error in SQL query: ' . pg_last_error());
  
David Morley's avatar
David Morley committed
35
  header('Location: https://' . $row[0]['domain']);
36
}