This commit is contained in:
2024-08-29 19:05:53 +05:30
commit 6073a08a6d
24 changed files with 1436 additions and 0 deletions

20
php/config.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
/* if you're working on localhost then you don't need to change anything
but if you're thinking to upload it to live server then you've to edit something
1. Paste your website url with forward slash(/) in the domain variable, you don't need
to write https://wwww. before the domain name if you have domain redirection setup
2. Change user, pass, db values accordingly mentioned in the comments below
3. Go to JavaScript file and search this keyword - let domain - then paste your url there
4. After all changes you've to wait because javascript file save changes may take time to reflect */
$domain = "https://localhost/web-Projects/url/"; //like this: codingnepalweb.com/
$host = "localhost";
$user = "root"; //Database username
$pass = ""; //Database password
$db = "urlShortener"; //Database name
$conn = mysqli_connect($host, $user, $pass, $db);
if(!$conn){
echo "Database connection error".mysqli_connect_error();
}
?>

15
php/delete.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
include "config.php";
if(isset($_GET['id'])){
$delete_id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = mysqli_query($conn, "DELETE FROM url WHERE shorten_url = '{$delete_id}'");
if($sql){
echo "success";
} else {
echo "error";
}
} else {
echo "error";
}
?>

23
php/url-controll.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
include "config.php";
$full_url = mysqli_real_escape_string($conn, $_POST['full_url']);
if(!empty($full_url) && filter_var($full_url, FILTER_VALIDATE_URL)){
$ran_url = substr(md5(microtime()), rand(0, 26), 5);
$sql = mysqli_query($conn, "SELECT * FROM url WHERE shorten_url = '{$ran_url}'");
if(mysqli_num_rows($sql) > 0){
echo "Something went wrong. Please generate again!";
}else{
$sql2 = mysqli_query($conn, "INSERT INTO url (full_url, shorten_url, clicks)
VALUES ('{$full_url}', '{$ran_url}', '0')");
if($sql2){
$sql3 = mysqli_query($conn, "SELECT shorten_url FROM url WHERE shorten_url = '{$ran_url}'");
if(mysqli_num_rows($sql3) > 0){
$shorten_url = mysqli_fetch_assoc($sql3);
echo $shorten_url['shorten_url'];
}
}
}
}else{
echo "$full_url - This is not a valid URL!";
}
?>