PHP Session et Cookies: Lire les Cookies

 
<?php
  $GLOBALS['username'] = "test";
  $GLOBALS['password'] = "test";
  
  setcookie ("cookie_user", "test", time()+60*60*24*30);
  setcookie ("cookie_pass", md5 ("test"), time()+60*60*24*30);
  
  function validatelogin (){
    if (strcmp ($_COOKIE['cookie_user'], $GLOBALS['username']) == 0 && strcmp ($_COOKIE['cookie_pass'], md5 ($GLOBALS['password'])) == 0){
      return true;
    } else {
      return false;
    }
  }
  
  if (validatelogin ()){
    echo "Successfully logged in.";
  } else {
    echo "Sorry, invalid login.";
  }
?>
  
  

PHP Session et Cookies: Lire les données du Cookies

 
<?php
  $user  = $_COOKIE['firstname'];
  $color = $_COOKIE['fontcolor'];
?>
<html>
 <head>
  
  <title>Get Cookie Data</title>
  
  <style type = "text/css">
   body { color: <?php echo( $color ); ?> }
 
  </style>
 </head>
 <body>
  <h1>Hello <?php echo( $user ); ?>! </h1>
 </body>
</html>
  
  

PHP: Ajouter le contenu d’un fichier dans String

 
Its syntax is: string fgets (int filepointer, int length)
<?
$fh = fopen("data.txt", "r");
while (! feof($fh)) :
     $line = fgets($fh, 4096);
     print $line."<br>";
endwhile;
fclose($fh);
?>
  
  

PHP: Lire un caractère d’un fichier

 
Its syntax is: string fgetc (int filepointer)
<?
$fh = fopen("data.txt", "r");
while (! feof($fh)) :
     $char = fgetc($fh);
     print $char;
endwhile;
fclose($fh);
?>
  
  

PHP: Lire un fichier mot par mot

 
<?php
$fh = fopen('novel.txt','r') or die($php_errormsg);
while (! feof($fh)) {
    if ($s = fgets($fh)) {
        $words = preg_split('/s+/',$s,-1,PREG_SPLIT_NO_EMPTY);
    }
}
fclose($fh) or die($php_errormsg);
?>
  
  

PHP: Lire le contenu d’un répertoire

<?php
    $dir = opendir("./");
                
    while ($read_file = readdir($dir)) {
      echo "$read_file", " ";
    }
    closedir($dir);
?>