Skip to content

Commit e9f5242

Browse files
authored
index.php - implement or indicate a need to fix the edge case that the shortened url (slug) is the same five characters s-t-a-t-s to access stats in the url route
1 parent 3b2ba26 commit e9f5242

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ function createLink() {
6969
$possible_slug = '';
7070
for($i = 0; $i < $slug_length; $i++) {
7171
$possible_slug .= $random_chars[rand(0, strlen($random_chars) - 1)];
72+
73+
// a randomly generated "stats" slug could break the url routing so override slug_length for this 1 in 26^5 probability chance that "stats" is the random string generated
74+
if($possible_slug=="stats"){
75+
$possible_slug .= $random_chars[rand(0, strlen($random_chars) - 1)];
76+
}
7277
}
7378
$result = mysqli_query($db, "SELECT COUNT(*) FROM links WHERE slug = '$possible_slug'") or error('Could not generate new slug.', 500);
7479
$row = mysqli_fetch_row($result);

0 commit comments

Comments
 (0)