no message
This commit is contained in:
11
Question09-MultipleFiles/Ex01.php
Normal file
11
Question09-MultipleFiles/Ex01.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex01 外部ファイル読み込み]
|
||||
*
|
||||
* TODO:
|
||||
* 1. __DIR__を使い、Util/Hello.phpをrequire_onceで読み込む
|
||||
* 2. 読み込んだHello.php内の getMessage() を呼び出し、
|
||||
* その戻り値を出力してください。
|
||||
*
|
||||
*/
|
||||
12
Question09-MultipleFiles/Ex02.php
Normal file
12
Question09-MultipleFiles/Ex02.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex02 エスケープ処理]
|
||||
*
|
||||
* TODO:
|
||||
* 1. __DIR__を使い、Util/Escape.phpをrequire_onceで読み込む
|
||||
* 2. URL経由で渡されたGETパラメータ "text" の値を取得する
|
||||
* ※例: http://example.com/Ex02_question.php?text=<script>alert('xss')</script>
|
||||
* 3. 取得した値を h() 関数でエスケープし、出力してください。
|
||||
*
|
||||
*/
|
||||
17
Question09-MultipleFiles/Ex03.php
Normal file
17
Question09-MultipleFiles/Ex03.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex03 複数値のリクエスト処理]
|
||||
*
|
||||
* TODO:
|
||||
* 1. __DIR__を使い、Util/Area.phpをrequire_onceで読み込む
|
||||
* 2. POSTで送られた以下の値を取得する
|
||||
* - 'vote' : 複数選択される可能性があるので配列で受け取る(例:$_POST['vote'])
|
||||
* - 'height' : 数値(縦)
|
||||
* - 'width' : 数値(横)
|
||||
* 3. 選択された各図形について、
|
||||
* - 値が1なら calcRectangle() を使い面積計算
|
||||
* - 値が2なら calcTriangle() を使い面積計算
|
||||
* 4. 計算結果を foreach などを用いて出力してください。
|
||||
*
|
||||
*/
|
||||
16
Question09-MultipleFiles/Ex04.php
Normal file
16
Question09-MultipleFiles/Ex04.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex04 認証チェックとリダイレクト]
|
||||
*
|
||||
* TODO:
|
||||
* 1. リクエストメソッドがPOSTであるかチェックしてください。
|
||||
* POST以外の場合は「POSTメソッドで送信してください」と出力してください。
|
||||
* 2. __DIR__ を使い、Util/Validate.php、Util/Redirect.php、Util/Escape.php を require_onceで読み込んでください。
|
||||
* 3. POSTで送信された "username" と "password" を取得してください。
|
||||
* 4. 取得した値を checkUser() 関数に渡し、認証チェックを行ってください。
|
||||
* 5. 認証成功なら、redirect() 関数を使い "Ex04_success.php" へリダイレクトしてください。
|
||||
* 6. 認証失敗なら、「認証に失敗しました。入力されたユーザー名:{username}」と出力してください。
|
||||
* ※{username}は h() を使ってエスケープしてください。
|
||||
*
|
||||
*/
|
||||
17
Question09-MultipleFiles/Ex04_success.php
Normal file
17
Question09-MultipleFiles/Ex04_success.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>認証成功</title>
|
||||
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>認証成功</h1>
|
||||
<p>おめでとう! 正しいユーザー情報が入力されました。</p>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
20
Question09-MultipleFiles/Ex05.php
Normal file
20
Question09-MultipleFiles/Ex05.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex05 セッションを使う + 画像アップロード]
|
||||
*
|
||||
* TODO:
|
||||
* 1. リクエストメソッドがPOSTであるかチェックしてください。
|
||||
* ※POST以外の場合は「POSTメソッドで送信してください」と出力してください。
|
||||
* 2. session_start() を呼び出し、セッションを開始してください。
|
||||
* 3. __DIR__ を使い、Util/Upload.php を require_onceで読み込んでください。
|
||||
* 4. $_FILES['image'] が存在するかチェックしてください。
|
||||
* 5. uploadImage() 関数を使用して、画像アップロード処理を行ってください。
|
||||
* ※アップロード先はプロジェクト内の "uploads" フォルダとします。
|
||||
* ※関数はアップロード成功時に画像のファイル名を返すものとします。
|
||||
* 6. アップロード成功なら、返されたファイル名を $_SESSION['uploaded_image'] に保存してください。
|
||||
* 7. 成功時は「画像アップロード成功:{ファイル名}」と出力してください。
|
||||
* ※{ファイル名}は実際のアップロードされた画像のファイル名に置き換えます。
|
||||
* 8. アップロードに失敗した場合は、「画像アップロードに失敗しました」と出力してください。
|
||||
*
|
||||
*/
|
||||
141
Question09-MultipleFiles/index.html
Normal file
141
Question09-MultipleFiles/index.html
Normal file
@@ -0,0 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>PHP 練習問題スタートページ</title>
|
||||
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>独習PHP第6・8章練習問題 <small>外部ファイル読み込みとリクエスト情報</small></h1>
|
||||
</div>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<!-- Ex01 -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex01.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex01: 外部ファイル読み込み
|
||||
</a>
|
||||
<small>初級</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ex02 -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex02.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex02: エスケープ処理
|
||||
</a>
|
||||
<small>初級</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ex03 -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseEx03">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex03: 複数値のリクエスト処理
|
||||
</a>
|
||||
<small>初級</small>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseEx03" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<form method="post" action="Ex03.php" target="_blank" class="form-inline">
|
||||
<div class="form-group">
|
||||
<label for="vote">図形</label>
|
||||
<select name="vote[]" multiple class="form-control">
|
||||
<option value="1">四角形</option>
|
||||
<option value="2">三角形</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="height">縦</label>
|
||||
<input type="number" name="height" class="form-control" placeholder="数値を入力">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="width">横</label>
|
||||
<input type="number" name="width" class="form-control" placeholder="数値を入力">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">計算する</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ex04 -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseEx04">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex04: 認証チェック(上級)
|
||||
</a>
|
||||
<small>上級</small>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseEx04" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<form method="post" action="Ex04.php" target="_blank" class="form-inline">
|
||||
<div class="form-group">
|
||||
<label for="username">ユーザー名</label>
|
||||
<input type="text" name="username" class="form-control" placeholder="ユーザー名を入力">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">パスワード</label>
|
||||
<input type="password" name="password" class="form-control" placeholder="パスワードを入力">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">ログイン</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ex05 -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseEx05">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex05: セッションを使う + 画像アップロード
|
||||
</a>
|
||||
<small>上級</small>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseEx05" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<form method="post" action="Ex05.php" target="_blank" class="form-inline"
|
||||
enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label for="image">画像ファイル</label>
|
||||
<input type="file" name="image" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">アップロード</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="../common/js/jquery-3.2.1.min.js"></script>
|
||||
|
||||
<!-- Bootstrap Core JavaScript -->
|
||||
<script src="../common/js/bootstrap.min"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
18
Question09-MultipleFiles/util/area.php
Normal file
18
Question09-MultipleFiles/util/area.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
// area.php:Ex03用
|
||||
|
||||
/**
|
||||
* 四角形の面積:縦×横
|
||||
*/
|
||||
function calcRectangle($height, $width)
|
||||
{
|
||||
return $height * $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* 三角形の面積:縦×横/2
|
||||
*/
|
||||
function calcTriangle($height, $width)
|
||||
{
|
||||
return ($height * $width) / 2;
|
||||
}
|
||||
9
Question09-MultipleFiles/util/escape.php
Normal file
9
Question09-MultipleFiles/util/escape.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
// escape.php:Ex02用
|
||||
/**
|
||||
* 文字列をエスケープする関数
|
||||
*/
|
||||
function h($str)
|
||||
{
|
||||
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
6
Question09-MultipleFiles/util/hello.php
Normal file
6
Question09-MultipleFiles/util/hello.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
// hello.php:Ex01用
|
||||
function getMessage()
|
||||
{
|
||||
return "Hello, world!";
|
||||
}
|
||||
12
Question09-MultipleFiles/util/redirect.php
Normal file
12
Question09-MultipleFiles/util/redirect.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// Util/redirect.php:Ex04/Ex05共通用
|
||||
/**
|
||||
* 指定したURLへリダイレクトする関数
|
||||
*
|
||||
* @param string $url リダイレクト先URL
|
||||
*/
|
||||
function redirect($url)
|
||||
{
|
||||
header("Location: " . $url);
|
||||
exit;
|
||||
}
|
||||
14
Question09-MultipleFiles/util/validate.php
Normal file
14
Question09-MultipleFiles/util/validate.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// Util/validate.php:Ex05用
|
||||
/**
|
||||
* ユーザー認証チェック関数
|
||||
* ユーザー名が "admin"、パスワードが "secret" の場合のみ認証成功
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool 認証成功ならtrue
|
||||
*/
|
||||
function checkUser($username, $password)
|
||||
{
|
||||
return ($username === 'admin' && $password === 'secret');
|
||||
}
|
||||
Reference in New Issue
Block a user