<?php session_start(); $_SESSION['username'] = "jason"; $_SESSION['loggedon'] = date("M d Y H:i:s"); $sessionVars = session_encode(); echo $sessionVars; ?> |
PHP Session et Cookies: Créer un Système de connexion à l’aide des Cookies
on_destroy (); } if (login ( "test", "test" )) { echo "Successfully logged in with user: " . $_SESSION ['user'] . " and pass: " . $_SESSION ['pass']; } else |
PHP Session et Cookies: Démarrer une session
<?php session_start(); ?> <html> <head> <title>Session running</title> <style type="text/css"> body { font-family:<?php echo $_SESSION['font']; ?> } </style> </head> <body> <h3>Preferred font family is <?php echo $_SESSION['font']; ?></h3> <a href="prefs3.php?<?php echo( SID ); ?>">Next page</a> </body> </html> |
PHP Session et Cookies: Enregistrer une variable dans la session
<?php $myvar = "This is my variable to store in the session"; $myvar_name = "myvar"; session_register($myvar_name); ?> |
PHP Session et Cookies: Lire une valeur dans les cookies
<?php if (isset($_COOKIE['flavor'])) { print "You ate a {$_COOKIE['flavor']} cookie."; } ?> |
PHP: Trouver le nombre de ligne d’un fichier
<?php $lines = 0; if ($fh = fopen('data.txt','r')) { while (! feof($fh)) { if (fgets($fh)) { $lines++; } } } print $lines; ?> |
PHP Session et Cookies: Parcouriri et afficher le contenu des Cookies
<?php foreach ($_COOKIE as $cookie_name => $cookie_value) { print "$cookie_name = $cookie_value <br/>"; } ?> |
PHP: Véfirier si élément est un fichier
<html> <head> <title>Is it a file: is_file()</title> </head> <body> <?php $file = "test.txt"; outputFileTestInfo( $file ); function outputFileTestInfo( $f ){ if ( ! file_exists( $f ) ){ print "$f does not exist<BR>"; return; } print "$f is ".(is_file( $f )?"":"not ")."a file<br>"; } ?> </body> </html> |
PHP: Vérifier si un email est correcte à l’aide des expressions régulières
g:</B>$string"; echo "<BR><B>regular expression:</B> $pattern"; if (get_magic_quotes_gpc()){ echo "<BR><BR>"; echo "<BR>Stripping magic quotes...." |
PHP: Vérifier si un fichier est exécutable
<html> <head> <title>Is the file executable: is_executable</title> </head> <body> <?php $file = "test.txt"; outputFileTestInfo( $file ); function outputFileTestInfo( $f ){ if ( ! file_exists( $f ) ){ print "$f does not exist<BR>"; return; } print "$f is ".(is_executable( $f )?"":"not ")."executable<br>"; } ?> </body> </html> |