root / _scripts / slug.php @ 4ba103f6
Historique | Voir | Annoter | Télécharger (1004 octets)
1 |
<?php
|
---|---|
2 |
|
3 |
/*
|
4 |
* Transforme un slub en adresse compatible pour le site
|
5 |
*/
|
6 |
|
7 |
include_once("../_config/config.php"); |
8 |
|
9 |
$url = $_SERVER["REQUEST_URI"]; |
10 |
|
11 |
$slug = substr($url,strrpos($url,"/")+1); |
12 |
//var_dump($slug);
|
13 |
|
14 |
$id = getId($slug); |
15 |
var_dump($id); |
16 |
|
17 |
if($id!=null) { |
18 |
$url = "Location: index.php?page=mur&id=$id"; |
19 |
} else {
|
20 |
$url = "Location: index.php?page=404"; |
21 |
} |
22 |
|
23 |
//var_dump($url);
|
24 |
header($url); |
25 |
|
26 |
|
27 |
function getId($slug) { |
28 |
$sql = "SELECT id_mur FROM mur WHERE slug='$slug'"; |
29 |
|
30 |
// Connexion à la BDD
|
31 |
try {
|
32 |
$db = new PDO('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.';charset=utf8', DATABASE_USER, DATABASE_PASSWORD); |
33 |
} catch (PDOException $e) { |
34 |
print "Erreur !: " . $e->getMessage(); |
35 |
die();
|
36 |
} |
37 |
|
38 |
// On recherche le slug dans la BDD pour réupérer l'id
|
39 |
try {
|
40 |
if ($query=$db->query($sql)) { |
41 |
$res = $query->fetch(PDO::FETCH_NUM); |
42 |
return($res[0]); |
43 |
} |
44 |
} catch (PDOException $e) { |
45 |
print "Erreur !: " . $e->getMessage(); |
46 |
die();
|
47 |
} |
48 |
} |
49 |
?>
|
50 |
|
51 |
|