Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetShortUrl($url){
- global $conn;
- $query = "SELECT * FROM url_shorten WHERE url = '".$url."' ";
- $result = $conn->query($query);
- if ($result->num_rows > 0) {
- $row = $result->fetch_assoc();
- return $row['short_code'];
- } else {
- $short_code = generateUniqueID();
- $sql = "INSERT INTO url_shorten (url, short_code, hits)
- VALUES ('".$url."', '".$short_code."', '0')";
- if ($conn->query($sql) === TRUE) {
- return $short_code;
- } else {
- die("Unknown Error Occured");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement