-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateposthash.php
34 lines (30 loc) · 1.11 KB
/
createposthash.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
<?php
define('INCLUDE_CHECK',true);
include 'connect.php';
$posts = mysqli_query($GLOBALS['sqllink'], "SELECT postid,hash FROM tbl_posts WHERE hash = ''");
$existing = array();
$query = mysqli_query($GLOBALS['sqllink'], "SELECT hash FROM tbl_posts WHERE 1");
if($query) {
while($row = mysqli_fetch_assoc($query)) {
$existing[] = $row['hash'];
}
}
while($post = mysqli_fetch_assoc($posts)) {
$newhash = generateRandomString(10);
while(in_array($newhash,$existing)) {
$newhash = generateRandomString(10);
}
mysqli_query($GLOBALS['sqllink'], "UPDATE tbl_posts SET hash = '" . $newhash . "' WHERE postid = " . $post['postid']);
copy("asinglepost_template.php", "singlepost_" . $newhash . ".php");
echo $post['postid'] . ": " . $newhash;
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>