vendredi, mars 29, 2024
Nom d'utilisateur : Mot de passe :
Les quickies sont des exemples de code, facilement intégrables à vos propres projets. De part la simplicité du code, il n'est pas envisageable d'en faire un "projet" à part.

N'hésitez pas à faire part de vos commentaires, et surtout amusez-vous bien !

[NEWS]
Envoyé par unreal
Le petit script php qui suit permet d'identifier le système d'exploitation utilisé par le visiteur. Il peut donc servir de base à un moteur de stats (en enregistrant les résultats dans une base de données à chaque accès, par exemple).

<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$user_agents = array('Windows NT 5.1', 'Windows NT 5.0', 'Windows 2000', 'Windows 98', 'Windows NT 4.0', 'Linux', 'Mac OS X', 'SunOS', 'FreeBSD', '');
$os = array('Windows XP', 'Windows 2000', 'Windows 2000', 'Windows 98', 'Windows NT 4.0', 'Linux', 'Mac OS X', 'Solaris', 'FreeBSD', 'Inconnu');

foreach ($user_agents as $i => $value)
    if(@strpos($user_agent, $value))
        break;

$user_os = $os[$i];
?>


Encore une fois, pour la démo fonctionnelle, c'est par ici !

Posté le 18/04/05 à 03:24 - 0 Commentaires...

[NEWS]
Envoyé par unreal
Il arrive souvent à ce qu'on ait besoin d'afficher un calendrier, alors voici un petit script prévu à cet effet. Il est multi-langue (il suffit de modifier la ligne setlocale), et parfaitement customisable.

<?php
$year = 2005;
$month = 7;

setlocale(LC_ALL, 'fr_FR.ISO8859-1');
echo (mycal($year, $month));

function mycal($year, $month) {
    $td = '<td>';
    $td_ = '</td>';
    $tr = '<tr>';
    $tr_ = '</tr>';
    $table = '<table>';
    $table_ = '</table>';

    $cal_header = strftime('%B, %Y', mktime(0, 0, 0, $month, 1, $year)) . "\n";

    $start_day = strftime('%u', mktime(0, 0, 0, $month, 1, $year));
    $days_in_month = date('j', mktime(0, 0, 0, $month + 1, 0, $year));

    $cal = "$table\n$tr";
    for ($i = 2 - $start_day ; $i <= 8 - $start_day ; $i++)
        $cal .= $td . ucfirst(strftime('%a', mktime(0, 0, 0, $month, $i, $year))) . $td_;
    $cal .= "$tr_\n$tr";

    $line_day = $start_day;
    $cal .= str_repeat($td . $td_, ($start_day - 1));

    for ($i = 1 ; $i <= $days_in_month ; $i++) {
        if ($line_day == 8) {
            $line_day = 1;
            $cal .= "$tr_\n$tr";
        }
        $cal .= $td . $i . $td_;
        $line_day++;
    }

    $cal .= "$tr_\n$table_";

    return("$cal_header\n<br /><br />\n$cal");
}
?>


Pour la démo (avec code source), c'est par ici !

Posté le 18/04/05 à 03:09 - 0 Commentaires...

2 pages... [1-5][6-7]