-
Notifications
You must be signed in to change notification settings - Fork 21
/
app.php
62 lines (55 loc) · 1.57 KB
/
app.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
<?php
include 'db.php';
include 'urlget.php';
session_start();
//Receving POST VARIABLES HERE
$username_value=$_POST['fname'];
$secretkey=$_POST['secretkey'];
$userid=$_POST['userid'];
//Giving POST VARIABLE SESSION
$_SESSION['secretkey']=$secretkey;
$_SESSION['userid']=$userid;
$_SESSION['username_value']=$username_value;
//Cookie Function
// function setcookievalue($secretkey,$userid) {
//
// }
if(!isset($_COOKIE['secretid']) && !isset($_COOKIE['userid']))
{
setcookie('secretid', $secretkey);
setcookie('userid', $userid);
setcookie('username', $username_value);
$newurl=$fdomain.$userid;
$_SESSION['newurl']=$newurl;
//API SHORTEN START
$site=$_SESSION['newurl'];
$url='https://cutt.ly/api/api.php';
$finallink = urlencode($site);
$key='0c8d5cebe5924b4f216d91fc761c19bc8d8d7';
$json = file_get_contents($url."?key=$key&short=$finallink");
$data = json_decode ($json, true);
$_SESSION['finalurl']=$data["url"]["shortLink"];
//API SHORTEN END
$sql = "INSERT INTO users (secret,username,userid) VALUES ('$secretkey','$username_value','$userid')";
if(mysqli_query($link, $sql)){
echo "Records inserted successfully.";
header("Location:".$newurl, true, 301);
}
}
else{
$nid=$_COOKIE['secretid']; //secret id stored in nid
$sqlb = "SELECT userid FROM users WHERE secret='$nid'";
$result = $link->query($sqlb);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$newurl=$fdomain.$row['userid'];
header("Location:".$newurl,true, 301);
}
}
else
{
header("Location:index.php");
}
}
?>