• Aucun résultat trouvé

6.Le fichier affichage.php qui affiche dans une seule page tous les articles de l'utilisateur choisi dans la page d'accueil

index.php

<!DOCTYPE html>

<html lang="fr">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

<title>Mon blog</title>

<meta name="keywords" content="Blog" />

<style type="text/css" title="styles css">

div.bord {border-width:3px;color:orange;style: double;background-image:url(bandeau.jpg);

width:100% height:120px;font-size: 80px;color:white;}

p {border-width:2px;color: blue;style: thick; background-#EEE;}

a{border-color: red; style: double; width: 2px;}

</style>

</head>

<body>

<div class="bord">Tous les Blogs</div>

<div><br />

<a href="inscription.php" >Créez votre propre blog: inscrivez vous!</a>&nbsp;

<a href="identification.php" >Ajoutez un article à votre propre blog</a>

</div>

<?php

include ("connexpdo.inc.php");

echo "<h2>Liste des blogs</h2>";

$idcom= connexpdo("blog","myparam");

$requete = "SELECT nom,id_user FROM user ORDER BY nom ASC";

$result=$idcom->query($requete);

while($ligne=$result->fetch(PDO::FETCH_BOTH)) {

echo "<br /><a href=\"affichage.php?id_user= ".$ligne[1]."\">". $ligne[0]."</a><br />";

}

?>

</body>

</html>

inscription.php

<!DOCTYPE html >

<html>

<head>

<meta charset="UTF-8" />

<title> Mon blog</title>

<style type="text/css" title="styles css">

body {font-size: 20px;} div.bord border-width:2px;color:orange;style: double;}

</style>

</head>

<body>

<div class="bord">

<img src="bandeau.jpg" alt="Mon blog" width="100%"/></div>

<form method="post" name="form1" action="inscription.php">

<fieldset>

<legend>Inscrivez vous pour créer votre blog</legend><br />

<label>Login </label>

<input type="text" id="login" name="login"/><br />

<label>Pass&nbsp;&nbsp;</label>

<input type="text" id="pass" name="pass"/><br /></>

<input type="submit" name="envoi" value=" Créer un compte " /><br />

</fieldset>

</form>

<?php

if(isset($_POST['login']) AND isset($_POST['pass']) ) {

include_once("connexpdo.inc.php");

if($idcom=connexpdo('blog','myparam')) {

echo "Connexion <br /> OK" ;

$nom=$idcom->quote($_POST['login']);

echo $nom,"<br />";

$pass=$idcom->quote($_POST['pass']);

echo $pass,"<br />";

$requete="INSERT INTO user VALUES('',$nom,$pass)";

if($result=$idcom->query($requete)) {echo "insertion OK <br />";}

} }

?>

</body>

</html>

identification.php

<!DOCTYPE html >

<html>

<head>

<meta charset="UTF-8" />

<title>Mon blog : IDENTIFICATION</title>

<style type="text/css" title="styles css">

body {font-size: 20px;}

div.bord {border-width:2px;color:orange;style: double;}

</style>

</head>

<body>

<div class="bord"><img src="bandeau.jpg" alt="Mon blog" width="100%"/></div>

<form method="post" name="form1" action="identification.php">

<fieldset>

<legend>Identifiez vous pour créer un article</legend><br />

<label>Login</label>

<input type="text" id="login" name="login"/><br /></>

<label>Pass</label>

<input type="text" id="pass" name="pass"/><br /></>

<input type="submit" name="envoi" value=" Vérifier " /><br />

</fieldset>

</form>

//

<?php

session_start();

if(!empty($_POST['login']) AND isset($_POST['pass'])) {

include_once("connexpdo.inc.php");

$idcom=connexpdo('blog','myparam');

$nom=$_POST['login'];

$pass=$_POST['pass'];

$requete="SELECT pass,id_user FROM user WHERE nom='$nom'";

$result=$idcom->query($requete);

$verif=$result->fetchObject();

$pass2=$verif->pass;

$id_user=$verif->id_user;

if($pass2==$pass) {

echo "Reconnu";

echo "<script type=\"text/javascript\">"."window.location='ecrire.php'"."</script>" ; $_SESSION['acces']="oui";

$_SESSION['id_user']=$id_user;

} }

?>

</body>

</html>

ecrire.php

<?php

session_start();

$acces=$_SESSION['acces'];

$id_user=$_SESSION['id_user'];

if($acces!="oui") {

echo "<script

type=\"text/javascript\">"."window.location='identification.html'"."</script>" ; }

?>

<!DOCTYPE html >

<html>

<head>

<meta charset="UTF-8" />

<title>Mon blog</title>

<style type="text/css" title="styles css">

div.bord {border-width:2px; color:orange; border-style: double; font-size: 20px;}

input, textarea{background-color: #EEE;}

</style>

</head>

<body>

<div class="bord">

<!-- <img src="bandeau.jpg" alt="Mon blog" /> -->

<h1>Mon blog</h1>

</div>

<form method="post" name="form1" action="stockage.php">

<h3>Nouvel article </h3>

<fieldset>

<legend>Titre</legend>

<input type="text" id="titre" name="titre" size="50"/>

<legend>Catégorie</legend>

<label>Actualité : </label>

<input type="radio" name="cat" value="actu" />&nbsp;&nbsp;

<label>Musique : </label>

<input type="radio" id="cat" name="cat" value="musique" />&nbsp;&nbsp;

<label>Cinéma : </label>

<input type="radio" id="cat" name="cat" value="cine" />&nbsp;&nbsp;

</fieldset>

<fieldset>

<legend>Votre texte</legend>

<input type="button" onclick="form1.texte.value +='<b>'" value="Gras"/>

<input type="button" onclick="form1.texte.value +='</b>'" value="Normal"/>

<textarea id="texte" name="texte" rows="10" cols="70">Votre Texte</textarea>

<input type="submit" id="envoi" name="envoi" value="Publier" />

</fieldset>

</form>

</body>

</html>

affichage.php

<!DOCTYPE html >

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

<title>Mon blog</title>

<style type="text/css" title="styles css">

div.bord,p {border-width:3px;color:orange;style: double;}

p {border-width:2px; color: blue; border-style: thick; background-color:#EEE;}

</style>

</head>

<body>

<div class="bord"> <img src="bandeau.jpg" width="100%" height="120px" alt="Mon blog"

/></div>

<?php

include ("connexpdo.inc.php");

$id_user= $_GET['id_user'];

//echo $id_user, "<br />";

$idcom= connexpdo("blog","myparam");

$requete = "SELECT titre,cat,texte,date FROM articles WHERE id_user=$id_user ORDER BY date DESC";

if($result=$idcom->query($requete)) {echo "Resultat";}

while($ligne=$result->fetch()) {

$date=date("d / m / Y ",$ligne[3]);

echo "<div><h3>Le ", $date, $ligne[0],"&nbsp;</h3><p>",$ligne[1],"<br />",

$ligne[2],"</p></div>";

}

?>

</body>

</html>

Le site est visible en fonctionnement réel à l’adresse suivante : http://www.funhtml.com

Toutes vos remarques peuvent être envoyées à l’adresse :

php5@funhtml.com