+ Reply to Thread
Results 1 to 1 of 1
  1. Cel mai simplu URL Shortener

    #1
    VIP ~TraNda~'s Avatar
    Member since
    Feb 2014
    Location
    WarGods
    Posts
    12,109
    Last username
    LiOn. ~JoK3r ~
    Blog Entries
    4
    Mentioned
    95 Post(s)
    Achievements Days Registered 4 Mentions Received 2 Mentions Received 1 Mentions Given 4 Mentions Given 3 Mentions Given 2 Mentions Given 1 Threads Rating Received 1
    Doneaza
    Sustine Comunitatea WarGods!
    Fii unul de-al nostru! Doneaza
    Doneaza in Cont Bancar
    Click aici pentru a face o Donatie

    Cel mai simplu URL Shortener

    Acest script:
    • nu necesita baza de date.
    • salveaza adresele in fisiere.
    • este cel mai simplu posibil si semnificativ mic ca dimensiune.

    Pentru inceput vom creea un fisier php cu numele index.php.

    Acum in fisier, pentru inceput vom face urmatoarele:
    • vom seta adresa site-ului nostru unde vrem sa redirectionam utilizatorul in cazul in care adresa specificata este invalida.
    • vom spune scriptului ca adresa este invalida daca nu a fost specificata.
    • vom spune scriptului ca adresa este invalida daca nu exista in script.

    Vom face aceste lucruri astfel:
    PHP Code:
    $adresa_site="https://www.wargods.ro/";
     
    if(isset(
    $_GET['redirect'])) {
    if(!empty(
    $_GET['redirect'])) {
    if(
    file_exists('adrese/'.$_GET['redirect'].'.txt')) {
     
    /////// aici va fi codul de recirectionare
     
    } else { exit(header('Location: '.$adresa_site)); }
    } else { exit(
    header('Location: '.$adresa_site)); }
    } else { exit(
    header('Location: '.$adresa_site)); } 
    Acum tot ce mai trebuie facut este sa facem un nou folder cu numele adrese unde vom adauga fisiere text ce vor contine adresele unde trebuie sa redirectionam utilizatorul.


    Mai ramane sa finalizam scriptul php din index.php si sa il facem ca atunci cand toate datele sunt corecte, sa redirectioneze unde trebuie:
    PHP Code:
    $adresa_site="https://www.wargods.ro/";
     
    if(isset(
    $_GET['redirect'])) {
    if(!empty(
    $_GET['redirect'])) {
    if(
    file_exists('adrese/'.$_GET['redirect'].'.txt')) {
    exit(
    header('Location: '.file_get_contents('adrese/'.$_GET['redirect'].'.txt')));
    } else { exit(
    header('Location: '.$adresa_site)); }
    } else { exit(
    header('Location: '.$adresa_site)); }
    } else { exit(
    header('Location: '.$adresa_site)); } 
    Si de asemenea sa facem un nou fisier cu numele .htaccess in care sa punem urmatoarele:
    PHP Code:
    RewriteEngine On
     
    RewriteRule 
    ^(.*)$ index.php?redirect=$[L,QSA
    Last edited by ~TraNda~; 27-11-2019 at 11:05 PM.
    -------------

    TraNda - WarGods | R.R.M - AngeL - LiOn. - pichacku - Jok3r - UnicA

    P A C E

    DISCORD: unknown.cfg


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Partners
Humble Monthly Bundle
Voucher PC-Garage