1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
class LitiiUrl
{
private $hash;
private $urlBrowser;
private $redirect;
public function generateLitiiKey($nbcar)//Génère une clé alléatoire
{
$string = "";
$chaine = "abcdefghijklmnopqrstuvwxyzABCDEFGJHIJKLMNOPQRSTUVWXYZ0123456789";//les caractères autorisés dans la clé.
srand((double)microtime()*1000000);
for($i = 0; $i < $nbcar; $i++)
{
$string .= $chaine[rand() % strlen($chaine)];
}
$this->hash=$string;
return $string;
}
public function getLitiiUrl()
{
$this->urlBrowser = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo '<br>'.$this->urlBrowser;
}
public function WriteDataBase()
{
$resultat=executeRequeteSQL("INSERT INTO tinyurl (url_utilisateur , url_reduite) VALUES('$this->urlBrowser' , '$this->hash')", 'Error : Litii Url Not write in database ');
return $resultat;
}
public function fecthDataBase()
{
$reponse = mysql_query('SELECT url_utilisateur , url_reduite FROM tinyurl WHERE url_reduite="'.$this->hash.'"');//Sélectionne tous les champs de la table tynirul lorsque le champ url_reduite est égal à YRfz3Z
while ($donnees = mysql_fetch_array($reponse))
{
echo '<br>'.'la cle est ' . $donnees['url_reduite'] . ' et l\'adresse correspondante est : '.$donnees['url_utilisateur'].'<br />';
$redirection=$donnees['url_utilisateur'];
}
}
}
?> |
Partager