forked from mikecao/shorty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
51 lines (43 loc) · 1.21 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
require './shortly.php';
require './config.php';
$shortly = new Shortly($hostname, $connection);
$shortly->set_chars($chars);
$shortly->set_salt($salt);
$shortly->set_padding($padding);
$shortly->set_site_specific($site_specific);
/**
* Ensure $target does not have protocol or trailing slash
*/
if (preg_match('/^https?:\/\//', $target)) {
$target = str_replace('https://', '', $target);
$target = str_replace('http://', '', $target);
}
if (preg_match('/\/$/', $target)) {
$target = str_replace('/', '', $target);
}
$shortly->set_target($target);
/**
* Ensure $long_redirect has protocol and trailing slash
*/
if (!preg_match('/^https?:\/\//', $long_redirect)) {
$long_redirect = 'https://' . $long_redirect;
}
if (!preg_match('/\/$/', $long_redirect)) {
$long_redirect = $long_redirect . '/';
}
$shortly->set_long_redirect($long_redirect);
/**
* Ensure $query_string starts with question mark
*/
if (isset($query_string) && !preg_match('/^$/', $query_string)) {
if (!preg_match('/^\?/', $query_string)) {
$query_string = '?' . $query_string;
}
$shortly->set_query_string($query_string);
}
$shortly->run();
?>