Questions & Answers

How in PHP Script Remove Other link and replace my website link of a link shortner

If any one try to short link in my website that time my website link replace his or her link please help me how can i do this with this code


include 'setup.php';
$connect = new mysqli($host, $dbuser, $dbpass, $dbname);
if (!$connect) {
    echo '<script>alert("DATABASE NOT CONNECTED")</script>';
function generateRandomString($length = 8) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    return $randomString;
if (isset($_GET['title'])) {
    $res = $connect->prepare("SELECT * FROM links WHERE title=?");
    $res->bind_param("s", $_GET['title']);
    $goto = $res->get_result()->fetch_array();
    $g = $goto[1];
    header ("Location: $g");
if (isset($_POST['shrt'])) {
    $title = generateRandomString();
    if (substr($_POST['textarea'], 0, 4) != "http") {
      $url = "http://".$_POST['textarea'];
    } else {
    $url = $_POST['textarea'];

    $previous =  "";
    $after = "&html_redirect=1";
    $res = $connect->prepare("INSERT INTO links VALUES('',?,?)");
    echo "<script>prompt('YOUR SHORTENED URL IS:', '". $previous.$siteurl."/".$title.$after."');</script>"; 

` Please Edit my Script According my requirement

2023-01-11 09:29:40
You need to explain specifically what problem you're having currently when you run the code. What did you expect to happen, and what happens instead? Be specific, and ensure you've debugged sufficiently to narrow down the problem in the code - remember we can't run the code, so you need to be clear about the issue. See also How to Ask. You can edit your post. Thanks
2023-01-11 09:29:40
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Answers(0) :