Fichier PDF

Partagez, hébergez et archivez facilement vos documents au format PDF

Partager un fichier Mes fichiers Boite à outils PDF Recherche Aide Contact



corrige web2 final 2013 .pdf



Nom original: corrige-web2-final-2013.pdf
Auteur: user

Ce document au format PDF 1.5 a été généré par Microsoft® Office Word 2007, et a été envoyé sur fichier-pdf.fr le 10/07/2014 à 22:53, depuis l'adresse IP 141.105.x.x. La présente page de téléchargement du fichier a été vue 1429 fois.
Taille du document: 285 Ko (5 pages).
Confidentialité: fichier public




Télécharger le fichier (PDF)









Aperçu du document


Développement Web 2 – NFA017
Abdallah EL Asmar

Corrigé de l’examen final - 2013

1. Librairies
1.1. db.php
<?php
$idcon=mysql_connect("localhost","user","pwd");
$idbase=mysql_select_db("myDB");
if (!$idcon || !$idbase )
die( "Connexion Impossible.");
?>
1.2. secured.php
<?php
session_start();
if (!isset ($_SESSION['username']) or !isset ($_SESSION['password'])){
header("Location: index.php");
}
?>
2. Members
2.1. index.php
<?php
session_start();
include("db.php");
if(isset($_POST['login'])) {
if (isset($_POST['username']) && isset ($_POST['password'])) {
$query= "SELECT * FROM members WHERE username='".$_POST['username']."'
AND password='".$_POST['password']."'" ;
$result= mysql_query($query) or die(mysql_error());
$donne = mysql_fetch_array($result) ;
if ( mysql_num_rows($result) != 0 ) {
$_SESSION['username']=$_POST['login'];
$_SESSION['password']=$_POST['password'];
$_SESSION['id']=$donne['id'];
header("Location: forum.php");
}
else { echo " Invalid username/password";}
}
else { echo " Invalid username/password"; }
}
?>
<html><body><table>
<form name="form" action="index.php" method="post" >
<tr> <td>Username </td><td><input type="text" name="username"></td> </tr>
<tr><td>Password</td><td><input type="text" name="password"></td> </tr>
<tr><td><input type="submit" name="login" value="Login"></td><td></td> </tr>
</form> <tr><td><a href="register.php">Register</a></td><td> </td></tr>
</table> </body> </html>
Page 1 of 5

Développement Web 2 – NFA017
Abdallah EL Asmar

Corrigé de l’examen final - 2013

2.2. register.php
<?php
include("db.php");
if(isset($_POST['register']) and isset($_POST['username']) and isset($_POST['username']) and
isset($_POST['email']) and
isset($_POST['birthdate']) and isset($_FILES['profile']) ){
$vuser = $_POST['username'];
$vpass = $_POST['password'];
$vcoun = $_POST['country'];
$vemail = $_POST['email'];
$vbirth = $_POST['birthdate'];
$vfirst = $_POST['firstname'];
$vlast = $_POST['lastname'];
$query = 'select * from members where username = "'.$vuser.'" or email = "'.$vemail.'"';
if ( mysql_num_rows($result) != 0 ) {
echo " Invalid username/email, already exists";
}
else { $vdate = date("Y-m-d",strtotime($vbirth));
$filename = "";
$reqInsert ='insert into members values ("","'.$vfirst.'", "'.$vlast.'","'.$vuser.'",
"'.$vpass.'", "'.$vdate.'", "'.$vemail.'", "'.$vcoun.'", "'.$filename.'")';
$insere = mysql_query($reqInsert) or die(mysql_error());
$vid = mysql_insert_id();
// $infosfile = pathinfo($_FILES['profile']['name']);
// $extension = $infosfile['extension'];
$fname = basename($_FILES['profile']['name']);
$extension = strstr($fname,".");
$filename ="images/"."ppic_".$vid.$extension;
$tmpName =$_FILES['profile']['tmp_name'];
move_uploaded_file($tmpName , $filename);
$reqUpdate = 'update members set profilePicture = "'.$filename.'" where id = "'.$vid.'" ';
$modifie = mysql_query($reqUpdate)or die(mysql_error());
header("Location: index.php");
}
}
?>
<HTML><BODY>
<form method="POST" action="register.php" enctype="multipart/form-data">
<table>
<tr><td>First Name </td><td><input type="text" value="" name="firstname"/></td><td> </td></tr>
<tr><td>Last Name </td><td><input type="text" value="" name="lastname"/></td><td></td></tr>
<tr><td>User Name </td><td><input type="text" value="" name="username"/></td><td></td></tr>
<tr><td>Password </td><td><input type="text" value="" name="password"/></td><td></td></tr>
<tr><td>Country </td><td><select name="country">
<?php
$qcoun="select * from countries";
$rcoun = mysql_query($qcoun) or die(mysql_error());
while( $donne= mysql_fetch_array($rcoun)) {
echo "<option value=\"".$donne['id']."\">".$donne['name']."</option>" ;
}
?>
Page 2 of 5

Développement Web 2 – NFA017
Abdallah EL Asmar

Corrigé de l’examen final - 2013

</select></td><td></td></tr>
<tr><td>E-mail </td><td><input type="text" name="email"/></td><td></td></tr>
<tr><td>Birth Date </td><td><input type="text" name="birthdate"/></td><td>
<i>mm/dd/yyyy</i></td></tr>
<tr><td>Profile Picture </td><td><input type="file" name="profile"/></td><td></td></tr>
<tr><td><input type="submit" name="register" value="Register"></td><td></td><td></td></tr>
</table>
</form></BODY></HTML>
3. Forum
3.1. forum.php
<?php
include ("secured.php");
include("db.php");
if(isset($_POST['post']) && isset($_POST['comment'])) {
$vid =$_SESSION['id'];
$vdate = date("Y-m-d");
$vcomment = $_POST['comment'];
$qins= 'insert into forum values ("","'.$vid.'", "'.$vdate.'", "'.$vcomment.'")';
$rins= mysql_query($qins) or die(mysql_error());
}
?>
<html> <body>
<table border ="2">
<tr><td>Member</td><td>Comment</td></tr>
<?php
$query = 'select postdate, posttext, firstname, lastname, email, code, profilepicture
from countries c, members m, forum f
where memberid = m.id and countryid = c.id
order by postdate asc';
$result = mysql_query ($query) or die(mysql_error());
while ($donne = mysql_fetch_array($result)) {
extract ($donne);
echo '<tr><td>'; echo $postdate.' '.$firstname. ' '. $lastname.'<br />' ;
echo $email.' ('.$code.')<br />';
echo '<img src="'.$profilepicture.'" width="50" height="50"/>';
echo '</td><td>'.$posttext.'</td>';
echo '</tr>';
}
?>
</table>;
<form name="form" action="forum.php" method="post" ><br />
Add comment <textarea name="comment" rows="4" cols="40"></textarea><br /><br />
<input type="submit" name="post" value="Post">
</form>
</body>
</html>
Page 3 of 5

Développement Web 2 – NFA017
Abdallah EL Asmar

Corrigé de l’examen final - 2013

3.2. Forum XML
3.3. Forum XSLT
Il faut ajouter au fichier « forum.xml » la ligne suivante :
<?xml-stylesheet type="text/xsl" href="forum.xsl"?>
Fichier « forum.xsl »
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="2">
<tr> <td>Member</td> <td>Comment</td> </tr>
<xsl:for-each select="forum/post">
<xsl:sort select="date" order="ascending"/>
<tr> <td> <xsl:value-of select="date"/> <xsl:value-of select="member"/> <br />
<xsl:value-of select="email"/> (<xsl:value-of select="country"/>)
</td>
<td><xsl:value-of select="comment"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

*******************************************************************************
*****************************************************************************
Pour tester les différentes pages, il faut créer la base de données et ses tables, de même il faut créer d’abord
l’utilisateur « user » avec le password « pwd » et il faut lui accorder les privilèges de création d’une base de
données.
Script de création de la base de données :
<?php
$connect = mysql_connect("localhost", "user", "pwd") or
die ("Check your server connection.");
$db = "CREATE DATABASE myDB";
if (mysql_query($db, $connect)) {
echo "Ok! Database created!";
mysql_select_db ("myDB");
//Define the Countries table
$query1 = "CREATE TABLE Countries ( id INT(3) AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
Page 4 of 5

Développement Web 2 – NFA017
Abdallah EL Asmar

Corrigé de l’examen final - 2013

code VARCHAR(3) NOT NULL,
isRTL BOOLEAN NOT NULL,
PRIMARY KEY(id))";
$result1 = mysql_query($query1) or die(mysql_error());
//Define the Members table
$query2 = "CREATE TABLE Members ( id INT(6) AUTO_INCREMENT,
firstname VARCHAR(20) NOT NULL,
lastname VARCHAR(20) NOT NULL,
userName VARCHAR(20) NOT NULL,
password VARCHAR(20) NOT NULL,
birthDate DATE NOT NULL,
email VARCHAR(50) NOT NULL,
countryId INT(3) NOT NULL references Countries (id),
profilePicture VARCHAR(50),
PRIMARY KEY(id))";
$result2 = mysql_query($query2) or die(mysql_error());
//Define the Forum table
$query3 = "CREATE TABLE Forum ( id INT(10) AUTO_INCREMENT,
memberId INT(6) NOT NULL references Members (id),
postDate DATE NOT NULL,
postText VARCHAR(100),
PRIMARY KEY(id))";
$result3 = mysql_query($query3) or die(mysql_error());
//insert into the Countries table
$qins = "insert into Countries (name, code, isRtl) values ( 'Liban', 'LEB', 'TRUE')";
$rins = mysql_query($qins) or die(mysql_error());
$qins = "insert into Countries (name, code, isRtl) values ( 'France', 'Fr', 'TRUE')";
$rins = mysql_query($qins) or die(mysql_error());
$qins = "insert into Countries (name, code, isRtl) values ( 'USA', 'USA', 'TRUE')";
$rins = mysql_query($qins) or die(mysql_error());
$qins = "insert into Countries (name, code, isRtl) values ( 'UK', 'UK', 'TRUE')";
$rins = mysql_query($qins) or die(mysql_error());
}
else echo "Sorry, try creating the database again.";
?>

Page 5 of 5


Documents similaires


Fichier PDF corrige web2 final 2013
Fichier PDF eu metalic ii application process
Fichier PDF 3e7t7lb
Fichier PDF cours l2 php mysql chap 2
Fichier PDF session et authentifiaction php mysql exercice code
Fichier PDF 161b php 04


Sur le même sujet..