[PHP] Link Obfuscator

Kryccc

Nuovo Utente
21 Set 2019
3
0
1
Buonasera a tutti,
premetto che non so scrivere i codici ed avrei bisogno del vostro aiuto.
Ho la necessita' di rendere una pagina irraggiungibile tramite link diretto.
L'unica soluzione che ho trovato online e' un piccolo script php che contiene due file

linkObfuscator.php

PHP:
<?php

/**
 *
 * @author Cerion Morgauin
 * @version $Id$
 * @copyright Enrico Marongiu (cerion _@_ tiscali _._ it) - 2004
*  linkObfuscator manages a simple way of validating links: starting from a session, an user can browse exclusively those links that are performed by this page. to do this, a random seed is generated and a special code (named go) is attached to each link.
* each page that has to be obfuscated needs this class and a $linkObfuscator::check() to validate the user.
 **/

class linkObfuscator
{
    var $seed=0;
    var $referralSeed=0;
    function linkObfuscator($referralSeed=false)
    {
        // new seed, to obfuscate new pages
           srand();
        $this->seed= rand();
        // old seed, to check access
        if($referralSeed===false or !is_numeric($referralSeed)) {
            $this->referralSeed=$referralSeed;
        } else if(is_numeric($_SESSION['referralSeed'])) {
            $this->referralSeed=$_SESSION['referralSeed'];
            $_SESSION['referralSeed']=$this->seed;
        }   
    }

    function _obfuscate($aLink,$aSeed)
    {
        $sep=(strpos('?',$aLink)===false)?'?':'&';
        return $aLink. $sep ."go=".md5($aSeed .$aLink);
    }
    
    function obfuscate($aLink)
    {
        return $this->_obfuscate($aLink,$this->seed);
    }
    
    function check($anObfuscatedLink)
    {
        $theLink=preg_replace('/(&|\?)go=(\w)+/','',$anObfuscatedLink);
        if($this->_obfuscate($theLink,$this->referralSeed)==$anObfuscatedLink)
            return true;
            
        return false;
    }
}
?>

e il file test.php

PHP:
<?php

/**
 *
 *@author Cerion Morgauin
 * @version $Id$
 * @copyright Enrico Marongiu (cerion _@_ tiscali _._ it) - 2004
*  linkObfuscator manages a simple way of validating links: starting from a session, an user can browse exclusively those links that are performed by this page. to do this, a random seed is generated and a special code (named go) is attached to each link.
* each page that has to be obfuscated needs this class and a $linkObfuscator::check() to validate the user.
 **/

require_once('linkObfuscator.class.php');

session_start();


$lO=new linkObfuscator($_SESSION['referralSeed']);
print "actual referral Seed:". $_SESSION['referralSeed'] ."<br />\n";
?>
<html><body>
<?
if ($lO->referralSeed) {
    if($lO->check($_SERVER['REQUEST_URI'])){
        print "checked link: ${_SERVER['REQUEST_URI']}<br />\n";
    }else{
        print "link invalid: ${_SERVER['REQUEST_URI']} \n";

    }
}
$_SESSION['referralSeed']=$lO->seed;
$newLink= preg_replace('/(&|\?)go=(\w)+/','',$_SERVER['REQUEST_URI']);
$newLinkObscured=$lO->obfuscate($newLink);

?>
<a href="<?=$newLinkObscured?>">Obscured</a>
</body>

ho caricato la cartella con i file nella root del sito.
La domanda e' questa, che codice devo aggiungere nella head della pagina che voglio offuscare per far si che lo script funzioni ?

Come ho detto non conosco il linguaggio php quindi gentilmente se mi potete indicare step by step cosa devo fare.
Ringrazio molto per il vostro aiuto.
K.
 
Solo questo:
PHP:
require_once('linkObfuscator.class.php');
session_start();
$lO=new linkObfuscator($_SESSION['referralSeed']);
if ($lO->referralSeed) {
    if(!$lO->check($_SERVER['REQUEST_URI'])){
       header('location:/');
       exit;
    }

}
 
@Kryccc
Da regolamento del forum le parole come hai messo tu "aiuto please" non sono ammesse nei titoli delle discussioni.
2.7 E' vietato aprire discussioni con titoli generici del tipo "Aiuto", "Help" o "Rispondete subito".
Pertanto prima di continuare leggi attentamente il regolamento del forum e quella della sezione dove posti!
Inoltre coreggi il titolo di questa discussione
Grazie
 
@Kryccc
Da regolamento del forum le parole come hai messo tu "aiuto please" non sono ammesse nei titoli delle discussioni.Pertanto prima di continuare leggi attentamente il regolamento del forum e quella della sezione dove posti!
Inoltre coreggi il titolo di questa discussione
Grazie
Ok fatto
 
Solo questo:
PHP:
require_once('linkObfuscator.class.php');
session_start();
$lO=new linkObfuscator($_SESSION['referralSeed']);
if ($lO->referralSeed) {
    if(!$lO->check($_SERVER['REQUEST_URI'])){
       header('location:/');
       exit;
    }

}
Ho provato ad usare il codice che hai indicato, ma non funziona, ho provato ad inserirlo sia nell head che nel body, ma nessun risultato.

Il creatore dello script l'unica indicazione che da e' questa :
* each page that has to be obfuscated needs this class and a $linkObfuscator::check() to validate the user.
forse dipende da questo ?

O sapete indicarmi qualche altro metodo per rendere il link irraggiungibile se qualcuno fa copia/incolla ?
 

Discussioni simili