-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.php
47 lines (33 loc) · 827 Bytes
/
config.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
<?php
$db = new mysqli('localhost','root','','url_s');
function generateRandomString($length = 10) {
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
/*
if(mysqli_errno($db)){
echo "conection failed";
}else{
echo "connect Success";
}
*/
if(isset($_GET['code'])){
//select code from database
//echo $_GET['code'];
$result = '';
$result = $db->prepare("SELECT * FROM urls WHERE short_url=?");
$result->bind_param("s",$_GET['code']);
$result->execute();
$goto = $result->get_result()->fetch_array();
if($goto){
header("Location: $goto[1]");
}else{
echo "";
}
}
?>