LoginSignup
0
0

More than 3 years have passed since last update.

webarenaでubuntu その54

Last updated at Posted at 2019-10-03

概要

webarenaでubuntu18.04やってみた。
練習問題やってみた。

練習問題

画像アクセスカウンターを表示、せよ。

サンプルコード

<?php
    $id = "test";
    $db = new PDO("mysql:host=localhost;dbname=mydb;", 'user', 'pass');
    if (!$db)
    {
        print "connect error!! <br>";
    }
    else
    {
        $sql = "UPDATE counter SET cnt = cnt + 1 WHERE id='$id'";
        $db->query($sql);
        $sql = "SELECT * FROM counter WHERE id='$id'";
        $rs = $db->query($sql);
        if (!$rs)
        {
            print "Error in database!! 0 <br>";
            print $sql;
        }
        else
        {
            $count = 0;
            while ($row = $rs->fetch())
            {
                $count = $row['cnt'];
            }
            header('Content-Type: image/gif');
            $im = imagecreatetruecolor(200, 50);
            $color = imagecolorallocate($im, 255, 255, 255);
            imagestring($im, 5, 10, 10, $count, $color);
            imagegif($im);
            imagedestroy($im);
        }
    }
?>

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0