-
Notifications
You must be signed in to change notification settings - Fork 0
/
goto.php
63 lines (51 loc) · 1.59 KB
/
goto.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
52
53
54
55
56
57
58
59
60
61
62
63
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "CREATE DATABASE myDB";
if ($conn ->query($sql) == TRUE){
echo("DataBase created successfully");
}
//Selecting the database
mysqli_select_db($conn, 'myDB');
$query1 = "CREATE TABLE PERSONS(
Pid int NOT NULL,
Views int,
Website VARCHAR(100) NOT NULL,
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(Pid, Website)
);";
if ($conn ->query($query1) == TRUE)
echo("Table created");
else
echo("Error creating table".$conn->error);
//Getting the redirected link
$link = $_GET['redirect'];
settype($link, "string");
//Insert if not exist else ignore
//Initializing Pid to 1 -- Can be changed later when user logins
$query2 = "INSERT IGNORE INTO PERSONS(Pid, Views, Website)
VALUES(1, 0, '$link');
";
//Starting viewcount with 1
if ($conn ->query($query2) == TRUE)
echo("Record created successfully");
else
echo("Error ".$conn->error);
//Updating the count by 1
$query3 = "UPDATE PERSONS SET Views = Views + 1 WHERE Pid = 1 AND Website = '$link';";
if ($conn ->query($query3) == TRUE)
echo("View Count updated successfully");
else
echo("Error ".$conn->error);
//Redirect link
header("Location: ".$_GET['redirect']);
$conn->close()
?>