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
| <?php
class ExempleUrl
{
private $hash;
private $urlBrowser;
private $redirect;
public function generateExempleKey($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 getExempleUrl()
{
$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 : Exemple Url Not write in database ');
return $resultat;
}
public function redirect()
{
$redirect=executeRequeteSQL('SELECT url_utilisateur , url_reduite FROM tinyurl WHERE url_reduite="'.$this->hash.'"', 'Error : Connexion database ');
######################################
}
}
?> |