-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
166 lines (141 loc) · 5.11 KB
/
create.php
File metadata and controls
166 lines (141 loc) · 5.11 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php session_start();
/*
(c) 2006 Reed Morse <firstname.lastname at gmail.com>
and Pau Santesmasses <firstname at lastname.net>
*/
if(isset($_SESSION['posturl'])){
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
}
require("functions.php");
require("configuration.php");
connect();
authenticate();
/* Begin Big Confusing URL thinger */
$string = '';
//$post_url = $_POST['args'];
/*if(isset($_GET['descriptor'])){
$descriptor = $_GET['descriptor'];
} else {
$descriptor = '';
}
if(isset($_GET['method'])){
$method = $_GET['method'];
} else {
$method = '';
}
if(isset($_GET['key-1'])){
$key1 = $_GET['key-1'];
} else {
$key1 = '';
}
if(isset($_GET['key-2'])){
$key2 = $_GET['key-2'];
} else {
$key2 = '';
}
if(isset($_GET['key-3'])){
$key3 = $_GET['key-3'];
} else {
$key3 = '';
}
if(isset($_GET['key-4'])){
$key4 = $_GET['key-4'];
} else {
$key4 = '';
}
*/
$descriptor = @$_GET['descriptor'];
$method = @$_GET['method'];
$key1 = @$_GET['key-1'];
$key2 = @$_GET['key-2'];
$key3 = @$_GET['key-3'];
$key4 = @$_GET['key-4'];
foreach($_POST as $key => $value){ // Thanks Tynan Smith!
$key .= "=";
$value .= "&";
$string .= $key.$value;
// Could we just impload instead?
}
$string = ereg_replace("args=", "", $string); // Fix goofy stuff
$string = ereg_replace("&_=&", "", $string); // Fix goofy stuff
$post_url = $string;
/* End Big Confusing URL thinger */
$descriptor = ereg_replace(" ", "", $descriptor); // We could just use the strip whitespace function...
// Figure out where on the server the new url will be
$where = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$where = substr_replace($where, "", -11); // Remove /create.php
if(!$post_url && !$_GET['post_url']) {
exit('You need to enter a url, silly.');
}
if($method == "int"){ // Auto
if(!($key_prime = parse_domain($post_url))){
exit('Invalid URL');
}
$key_prime = ereg_replace("\.[a-z]+", "", $key_prime);
// Check to see if that domain has already been used as a first-level keyword.
$query_check = "SELECT * FROM `".$main_table."` WHERE `key1`='".$key_prime."'";
$result_check = mysql_query($query_check);
$rows = @mysql_num_rows($result_check);
if($rows){
// Go one keyword level deeper.
$query_check .= " AND `key2`='".$descriptor."'";
$result_check = mysql_query($query_check);
$rows = @mysql_num_rows($result_check);
// Check again.
if($rows){
// Not going to work. Use a different descriptor.
echo 'Oh dear. That Shorty already exists.';
} else {
$query_insert = "INSERT INTO `".$main_table."` (`target`, `day`, `month`, `year`, `key1`, `key2`) VALUES ('".$post_url."', '".date('j')."', '".date('n')."', '".date('Y')."', '".$key_prime."', '".$descriptor."')";
mysql_query($query_insert);
// Could add some confirmation sql here.
echo '<a href="'.$where.'/'.$key_prime.'/'.$descriptor.'/">'.$where.'/'.$key_prime.'/'.$descriptor.'/</a>';
}
} else {
$query_insert = "INSERT INTO `".$main_table."` (`target`, `day`, `month`, `year`, `key1`) VALUES ('".$post_url."', '".date('j')."', '".date('n')."', '".date('Y')."', '".$key_prime."')";
mysql_query($query_insert);
// Could add some confirmation sql here.
echo '<a href="'.$where.'/'.$key_prime.'/">'.$where.'/'.$key_prime.'/</a>';
}
// /
}
if($method == "rand"){ // Random
$integer = rand(10000, 99999);
// Make a loop that checks the integer and recreates the integer if it already exists.
// Might be smarter to just do them numerically
while(is_row($integer)){
$integer = rand(10000, 99999);
}
// Create Shorty when integer hasn't already been used
if(!is_row($integer)){
$query_insert = "INSERT INTO `".$main_table."` (`target`, `day`, `month`, `year`, `key1`) VALUES ('".$post_url."', '".date('j')."', '".date('n')."', '".date('Y')."', '".$integer."')";
mysql_query($query_insert);
// Could add some confirmation sql here.
echo '<a href="'.$where.'/'.$integer.'/">'.$where.'/'.$integer.'/</a>';
}
}
if($method == "desc"){
// Check to see if the specified keywords have already been used.
$query_check = "SELECT * FROM `".$main_table."` WHERE `key1`='".$key1."' AND `key2`='".$key2."' AND `key3`='".$key3."' AND `key4`='".$key4."'";
$result_check = mysql_query($query_check);
$rows = @mysql_num_rows($result_check);
if($rows){
// Whoops it already exists.
echo 'Oh dear. That Shorty already exists.';
} else {
$query_insert = "INSERT INTO `".$main_table."` (`target`, `day`, `month`, `year`, `key1`, `key2`, `key3`, `key4`) VALUES ('".$post_url."', '".date('j')."', '".date('n')."', '".date('Y')."', '".$key1."', '".$key2."', '".$key3."', '".$key4."')";
mysql_query($query_insert);
// Could add some confirmation sql here.
// Set up the keywords to make an easy url.
if(!$key2){ $key2 = ''; } else { $key2 = '/'.$key2; }
if(!$key3){ $key3 = ''; } else { $key3 = '/'.$key3; }
if(!$key4){ $key4 = ''; } else { $key4 = '/'.$key4; }
// /
echo '<a href="'.$where.'/'.$key1.$key2.$key3.$key4.'/">'.$where.'/'.$key1.$key2.$key3.$key4.'/</a>';
}
}
?>