{$text['title']}\n"; if($result){ echo "
\n"; while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $guestbookID= $row['guestbookID']; $title= $row['title']; $content= $row['content']; echo "
$title
$content
\n" ; //echo "
$title
$content
\n" ; } echo "
\n"; } else{ echo mysql_error(); echo $text['empty-guestbook']."\n"; } } /* Displays an empty form for typing the content of a new line in the guestbook */ function displayadd(){ global $text; global $conn; $query = "select * from user"; $result = mysql_query($query , $conn); $uid = $_SESSION['userID']; if(isset($_SESSION['userID'])){ echo "

{$text['add-comment']}

\n"; echo ""; echo "{$text['add-title']}
\n"; echo "{$text['add-message']}
\n"; echo $text['add-dest'].":"; echo "\n"; echo ""; echo "
"; } } function displaysearch(){ global $text; echo "

{$text['search-title']}

\n"; if(isset($_REQUEST['search'])){ echo $text['searched-string']." = ".$_REQUEST['search']."
\n"; echo $text['search-text']." \n"; } else{ echo $text['search-text']." \n"; } echo ""; echo "
"; } function validate($user,$pwd){ global $conn; global $message; $query = "select * from user where username='$user' and password = '$pwd'"; $result = mysql_query($query , $conn); $uid=0; if($result){ if($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $uid=$row['userID']; } } else{ die("Erreur de syntaxe SQL"); } return $uid; } function login(){ global $text; global $message; if(isset($_REQUEST['username']) and isset($_REQUEST['password'])){ $userID = validate($_REQUEST['username'], $_REQUEST['password']); if($userID){ $_SESSION['userID']=$userID; $_SESSION['username']=$_REQUEST['username']; return; } else{ $message=$text['login-error-message']; return; } } } function logout(){ unset($_SESSION['userID']); } function displaylogin(){ global $text; echo "
\n"; if(isset($_SESSION['userID'])){ echo "{$text['logged-in-message']}".$_SESSION['username'].""; echo "

{$text['logout-title']}

"; echo ""; } else{ echo "

{$text['login-title']}

"; echo $text['login-username']."
\n"; echo $text['login-pwd']."
\n"; echo ""; } echo "
"; } /* Inserts a new record in the table "guestbook". */ function addelement($title, $message, $user,$dest){ global $text; global $conn; $query = "INSERT INTO `guestbook` (`guestbookID` , `title` , `content`,`author`,`dest` ) VALUES ( NULL , '$title', '$message','$user','$dest');"; $result = mysql_query($query , $conn); if($result){ echo "

{$text['add-OK']}

\n"; } else{ echo "

{$text['add-error']}

\n"; } } function displayModifyPassword(){ global $text; if(isset($_SESSION['userID'])){ echo "

{$text['modify-title']}

\n"; $uid = $_SESSION['userID']; echo ""; echo $text['modify-pwd1']."
\n"; echo $text['modify-pwd1']."
\n"; echo ""; echo "
"; } } function modifyPassword(){ global $text; global $message; global $conn; global $logfile; if(isset($_REQUEST['pwd1']) and isset($_REQUEST['pwd2']) and isset($_REQUEST['userID'])){ $pwd1 = $_REQUEST['pwd1']; $pwd2 = $_REQUEST['pwd2']; $uid = $_REQUEST['userID']; if($pwd1 != $pwd2){ $message = $text['modify-error']; return; } $query = "UPDATE `myguestbook2`.`user` SET `password` = '$pwd1' WHERE `user`.`userID` ='$uid' LIMIT 1 ;"; $result = mysql_query($query , $conn); } $val="echo new pwd= {$_REQUEST['pwd1']} >> $logfile"; system($val); } function displayCSS(){ echo ""; } function printItem($number){ global $conn; global $text; $query = "select username, guestbook.* from user, guestbook where guestbookID=$number AND guestbook.author=userID"; $result = mysql_query($query , $conn); // echo $query."
\n"; if($result){ if($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $guestbookID= $row['guestbookID']; $title= $row['title']; $content= $row['content']; $author= $row['username']; $dest = $row['dest']; if($dest == 0){ $destination=$text['item-dest-public']; } else{ $destination=$text['item-dest-private']."($dest)"; } echo "

$title

$content
\n" ; $itemAuthor = $text['item-author']; echo "
$itemAuthor : $author"; echo "
$destination
\n"; } else{ echo mysql_error(); echo $text['item-error']; } } else{ //echo "Query=$query
"; echo mysql_error(); } } function displayLanguageChoice(){ global $lang_list; global $text; echo '
'; foreach($lang_list as $lang){ $language= $text[$lang]; echo "$language \n"; } echo '
'; } // Main program // We first test if a content should be inserted or not in the DB // If yes, we send the content to the DB // Then we display the list of everything that is in the DB // And finaly the form for new entries is displayed. // Load the language file if(!isset($_SESSION['language'])){ $_SESSION['language']='english'; } if (isset($_REQUEST['lang'])){ if($secure){ if(in_array($_REQUEST['lang'],$lang_list)){ $_SESSION['language']=$_REQUEST['lang']; } } else{ $_SESSION['language']=$_REQUEST['lang']; } } require_once($_SESSION['language'].'.php'); if (isset($_REQUEST['title']) and isset($_REQUEST['message']) and isset($_REQUEST['dest'])){ addelement($_REQUEST['title'],$_REQUEST['message'],$_REQUEST['userID'],$_REQUEST['dest']); } $message=""; modifyPassword(); login(); if (isset($_REQUEST['logout'])){ logout(); } //////////////////////////// // Main Document /////////////////////////// echo "Guest Book for Web Security"; displayCSS(); echo "\n"; echo ""; echo "
"; echo "
"; echo "

My Guest Book

"; displayLanguageChoice(); displaysearch(); echo "
"; // id=top echo "
"; displaylogin(); echo "
"; // id=leftnav echo "
"; displayModifyPassword(); echo "
"; // id=rightnav echo "
"; if(isset($_REQUEST['id'])){ printItem($_REQUEST['id']); } else{ printlist(); } echo "
"; // id=content echo " "; // id=container echo ""; ?>