diff --git a/asial-oop/Application.php b/asial-oop/Application.php
index cfeee86..d240b79 100644
--- a/asial-oop/Application.php
+++ b/asial-oop/Application.php
@@ -2,16 +2,15 @@
class Application
{
- private $logger;
+ private $logger;
- public function setLogger(FileLogger $logger)
- {
- $this->logger = $logger;
- }
+ public function setLogger(FileLogger $logger)
+ {
+ $this->logger = $logger;
+ }
- public function log($message)
- {
- $this->logger->log($message);
- }
+ public function log($message)
+ {
+ $this->logger->log($message);
+ }
}
-
diff --git a/asial-oop/Employee.php b/asial-oop/Employee.php
index 5d120e2..e2e71f9 100644
--- a/asial-oop/Employee.php
+++ b/asial-oop/Employee.php
@@ -2,38 +2,31 @@
class Employee extends Person
{
-
- private $base_salary = 200000;
- private $annual_pay_rise = 10000;
- private $service_years = 0;
-
- public function __construct($name, $service_years)
- {
- $this->setName($name);
- // parent::__construct($name); // 親のコンストラクタを呼ぶ
- $this->setServiceYears($service_years);
- }
-
- public function setServiceYears($service_years)
- {
- $this->service_years = $service_years;
- }
-
- public function getSalary()
- {
- $salary = $this->base_salary + ($this->annual_pay_rise * $this->service_years);
- return $salary;
- }
-
- public function displaySalary()
- {
- echo $this->getName() . 'さんの給与は' . number_format($this->getSalary()) . '円です';
- }
-
+ private $base_salary = 200000;
+ private $annual_pay_rise = 10000;
+ private $service_years = 0;
+
+ public function __construct($name, $service_years)
+ {
+ $this->setName($name);
+ // parent::__construct($name); // 親のコンストラクタを呼ぶ
+ $this->setServiceYears($service_years);
+ }
+
+ public function setServiceYears($service_years)
+ {
+ $this->service_years = $service_years;
+ }
+
+ public function getSalary()
+ {
+ $salary = $this->base_salary + ($this->annual_pay_rise * $this->service_years);
+
+ return $salary;
+ }
+
+ public function displaySalary()
+ {
+ echo $this->getName().'さんの給与は'.number_format($this->getSalary()).'円です';
+ }
}
-
-
-
-
-
-
diff --git a/asial-oop/Exception.php b/asial-oop/Exception.php
index a100644..9513639 100644
--- a/asial-oop/Exception.php
+++ b/asial-oop/Exception.php
@@ -1,15 +1,12 @@
getMessage();
+ echo $e->getMessage();
}
-
-
-
diff --git a/asial-oop/FileLogger.php b/asial-oop/FileLogger.php
index 75ff514..4a1dc62 100644
--- a/asial-oop/FileLogger.php
+++ b/asial-oop/FileLogger.php
@@ -2,23 +2,22 @@
class FileLogger
{
- private $path = '';
+ private $path = '';
- public function __construct($path)
- {
- $this->setPath($path);
- }
+ public function __construct($path)
+ {
+ $this->setPath($path);
+ }
- public function setPath($path)
- {
- $this->path = $path;
- }
+ public function setPath($path)
+ {
+ $this->path = $path;
+ }
- public function log($message)
- {
- file_put_contents($this->path, $message . PHP_EOL, FILE_APPEND);
- // PHP_EOL # 改行
- // FILE_APPEND # 第3引数に記述すると追記モード
- }
-
-}
\ No newline at end of file
+ public function log($message)
+ {
+ file_put_contents($this->path, $message.PHP_EOL, FILE_APPEND);
+ // PHP_EOL # 改行
+ // FILE_APPEND # 第3引数に記述すると追記モード
+ }
+}
diff --git a/asial-oop/Mail.php b/asial-oop/Mail.php
index 2d1dfff..1053a05 100644
--- a/asial-oop/Mail.php
+++ b/asial-oop/Mail.php
@@ -2,15 +2,15 @@
class Mail
{
- private $sender;
+ private $sender;
- public function setSender(IMailSender $sender)
- {
- $this->sender = $sender;
- }
+ public function setSender(IMailSender $sender)
+ {
+ $this->sender = $sender;
+ }
- public function send($message)
- {
- $this->sender->send($message);
- }
-}
\ No newline at end of file
+ public function send($message)
+ {
+ $this->sender->send($message);
+ }
+}
diff --git a/asial-oop/MailSender.php b/asial-oop/MailSender.php
index a13cb20..c926fe1 100644
--- a/asial-oop/MailSender.php
+++ b/asial-oop/MailSender.php
@@ -2,21 +2,21 @@
interface IMailSender
{
- public function send($message);
+ public function send($message);
}
class MailSender implements IMailSender
{
- public function send($message)
- {
- echo 'メールを送ります:' . $message;
- }
+ public function send($message)
+ {
+ echo 'メールを送ります:'.$message;
+ }
}
class DebugMailSender implements IMailSender
{
- public function send($message)
- {
- echo 'メールを送りません' . $message;
- }
-}
\ No newline at end of file
+ public function send($message)
+ {
+ echo 'メールを送りません'.$message;
+ }
+}
diff --git a/asial-oop/Person.php b/asial-oop/Person.php
index 8881561..da4a959 100644
--- a/asial-oop/Person.php
+++ b/asial-oop/Person.php
@@ -1,47 +1,45 @@
setName($name);
- $this->setAge($age);
+ $this->setName($name);
+ $this->setAge($age);
}
public function __destruct()
{
- echo 'さようなら';
+ echo 'さようなら';
}
public function setName($name)
{
- $this->name = trim($name);
+ $this->name = trim($name);
}
public function getName()
{
- return $this->name;
+ return $this->name;
}
public function setAge($age)
{
- $this->age = trim($age);
+ $this->age = trim($age);
}
public function sayHello()
{
- echo 'こんにちは、' . $this->name . 'です。';
- echo '年齢は' . $this->age . '歳です。';
+ echo 'こんにちは、'.$this->name.'です。';
+ echo '年齢は'.$this->age.'歳です。';
/*
if ($this->age !== '') {
echo '年齢は' . $this->age . '歳です。';
}
*/
-
}
-
}
diff --git a/asial-oop/application_client.php b/asial-oop/application_client.php
index 0cdbe37..ab12983 100644
--- a/asial-oop/application_client.php
+++ b/asial-oop/application_client.php
@@ -1,10 +1,10 @@
log('アプリケーション起動');
$app->log('処理を受け付けました');
$app->log('アプリケーション終了');
-
-
diff --git a/asial-oop/employee_client.php b/asial-oop/employee_client.php
index 935221b..06a44e1 100644
--- a/asial-oop/employee_client.php
+++ b/asial-oop/employee_client.php
@@ -4,11 +4,10 @@
//ini_set( 'display_errors', 0 );
// エラー出力する場合
-ini_set( 'display_errors', 1 );
+ini_set('display_errors', 1);
-
-require_once('Person.php');
-require_once('Employee.php');
+require_once 'Person.php';
+require_once 'Employee.php';
$taro = new Employee('アシアル太郎', 20);
$taro->displaySalary();
diff --git a/asial-oop/index.php b/asial-oop/index.php
index 5d58855..5caf36f 100644
--- a/asial-oop/index.php
+++ b/asial-oop/index.php
@@ -1,6 +1,6 @@
sayHello();
//echo 'test';
diff --git a/asial-oop/strategy_client.php b/asial-oop/strategy_client.php
index c3a96ab..30b1106 100644
--- a/asial-oop/strategy_client.php
+++ b/asial-oop/strategy_client.php
@@ -1,10 +1,10 @@
setSender(new DebugMailSender());
diff --git a/asial/array.php b/asial/array.php
index bbd6e9e..18938aa 100644
--- a/asial/array.php
+++ b/asial/array.php
@@ -1,16 +1,14 @@
";
- var_dump($uranai);
- print "
";
-
-?>
+ echo '
';
+ var_dump($uranai);
+ echo '
';
diff --git a/asial/break.php b/asial/break.php
index b78ac89..844ad4f 100644
--- a/asial/break.php
+++ b/asial/break.php
@@ -1,14 +1,13 @@
100) {
- break;
- }
- print $i . "
";
- }
+ // continue, break サンプル
+ for ($i = 1; $i <= 200; $i++) {
+ if ($i % 2 == 0) {
+ continue;
+ }
+ if ($i > 100) {
+ break;
+ }
+ echo $i.'
';
+ }
diff --git a/asial/check.php b/asial/check.php
index 1cc3467..374d7e8 100644
--- a/asial/check.php
+++ b/asial/check.php
@@ -1,10 +1,11 @@
";
print "備考は" . nl2br($_POST['note']);
-*/
+*/
?>
@@ -49,61 +50,65 @@ function h($str) {
$note_len) {
- $errors[] = "備考の文字数は" . $note_len . "文字以内にしてください";
+if (!isset($_POST['note']) || trim($_POST['note']) == '') {
+ $errors[] = '備考がセットされていません';
+} elseif (mb_strlen($_POST['note']) > $note_len) {
+ $errors[] = '備考の文字数は'.$note_len.'文字以内にしてください';
}
if (count($errors)) {
-?>
+ ?>
エラーがあります
", $errors);
+ echo implode('
', $errors);
} else {
- // メールを送る
- $body = "アンケート情報が入力されました\n";
- $body .= "名前:" . $_POST['name'] . "\n";
- $body .= "性別:" . $_POST['gender'] . "\n";
- $body .= "備考:" . $_POST['note'] . "\n";
+ // メールを送る
+ $body = "アンケート情報が入力されました\n";
+ $body .= '名前:'.$_POST['name']."\n";
+ $body .= '性別:'.$_POST['gender']."\n";
+ $body .= '備考:'.$_POST['note']."\n";
- // PHP側の言語設定を日本語/UTF-8で上書きする
- mb_language("Japanese");
- mb_internal_encoding("UTF-8");
- mb_send_mail("test@exsample.com", "アンケート情報", $body);
+ // PHP側の言語設定を日本語/UTF-8で上書きする
+ mb_language('Japanese');
+ mb_internal_encoding('UTF-8');
+ mb_send_mail('test@exsample.com', 'アンケート情報', $body);
-?>
+ ?>
入力を受け付けました
diff --git a/asial/date-after30.php b/asial/date-after30.php
index a4d6456..d438cec 100644
--- a/asial/date-after30.php
+++ b/asial/date-after30.php
@@ -3,13 +3,11 @@
// 30日後を取得
// 曜日を取得
-$xday = 30;
-$now = time() + 60 * 60* 24;
+$xday = 30;
+$now = time() + 60 * 60 * 24;
$feature = $now * $xday;
-$weekday = array("日","月","火","水","木","金","土");
-
-print date("Y/m/d", $feature);
-print '(' . $weekday[date("w", $feature)] . ')';
-
+$weekday = ['日', '月', '火', '水', '木', '金', '土'];
+echo date('Y/m/d', $feature);
+echo '('.$weekday[date('w', $feature)].')';
diff --git a/asial/fizzbuzz.php b/asial/fizzbuzz.php
index 56dc150..38cf102 100644
--- a/asial/fizzbuzz.php
+++ b/asial/fizzbuzz.php
@@ -2,19 +2,18 @@
// FizzBuzz
- $i = 1;
+ $i = 1;
- while ($i <= 100) {
-
- if ($i % 3 == 0 && $i % 5 == 0) {
- print "FizzBuzz";
- } else if ($i % 3 == 0) {
- print "Fizz";
- } else if ($i % 5 == 0) {
- print "Buzz";
- } else {
- print "$i";
- }
- print "
";
- $i++;
- }
+ while ($i <= 100) {
+ if ($i % 3 == 0 && $i % 5 == 0) {
+ echo 'FizzBuzz';
+ } elseif ($i % 3 == 0) {
+ echo 'Fizz';
+ } elseif ($i % 5 == 0) {
+ echo 'Buzz';
+ } else {
+ echo "$i";
+ }
+ echo '
';
+ $i++;
+ }
diff --git a/asial/foreach2.php b/asial/foreach2.php
index c845572..2eb18e1 100644
--- a/asial/foreach2.php
+++ b/asial/foreach2.php
@@ -2,21 +2,19 @@
// 多次元配列のforeach
- $members[1]['name'] = "アシアル太郎";
- $members[1]['age'] = 26;
- $members[1]['gender'] = "男";
+ $members[1]['name'] = 'アシアル太郎';
+ $members[1]['age'] = 26;
+ $members[1]['gender'] = '男';
- $members[2]['name'] = "アシアル花子";
- $members[2]['age'] = 28;
- $members[2]['gender'] = "女";
+ $members[2]['name'] = 'アシアル花子';
+ $members[2]['age'] = 28;
+ $members[2]['gender'] = '女';
- foreach ($members as $key => $member) {
-
- // print $key . "は" . $value . "です
";
-
- foreach ($member as $key2 => $value2) {
- print $key2 . "は" . $value2 . "です
";
- }
- }
+ foreach ($members as $key => $member) {
+ // print $key . "は" . $value . "です
";
+ foreach ($member as $key2 => $value2) {
+ echo $key2.'は'.$value2.'です
';
+ }
+ }
diff --git a/asial/function.php b/asial/function.php
index 685deb6..a6d1315 100644
--- a/asial/function.php
+++ b/asial/function.php
@@ -1,8 +1,6 @@
";
+echo power_rate(40, 24).'円
';
// ドライヤーを安い電気料金で1時間稼働させた場合
-print power_rate(1200, 1, 20) . "円
";
-
-
+echo power_rate(1200, 1, 20).'円
';
diff --git a/asial/function_htmlaspecialchars.php b/asial/function_htmlaspecialchars.php
index 698aa08..e19c22c 100644
--- a/asial/function_htmlaspecialchars.php
+++ b/asial/function_htmlaspecialchars.php
@@ -1,11 +1,10 @@
\ No newline at end of file
+ //$age = 18;
+ $age = $_GET['age'];
+
+ if ($age < 20) {
+ echo '未成年にはお酒を提供できません';
+ } else {
+ echo 'お酒はほどほどに';
+ }
diff --git a/asial/index.php b/asial/index.php
index 687eb76..d25c341 100644
--- a/asial/index.php
+++ b/asial/index.php
@@ -6,8 +6,8 @@
phpinfo
diff --git a/asial/member.php b/asial/member.php
index 43588e8..1f80200 100644
--- a/asial/member.php
+++ b/asial/member.php
@@ -2,18 +2,16 @@
// 配列テスト
- $member1['name'] = "アシアル太郎";
- $member1['age'] = 26;
- $member1['gender'] = "男";
+ $member1['name'] = 'アシアル太郎';
+ $member1['age'] = 26;
+ $member1['gender'] = '男';
- $member2['name'] = "アシアル花子";
- $member2['age'] = 28;
- $member2['gender'] = "女";
+ $member2['name'] = 'アシアル花子';
+ $member2['age'] = 28;
+ $member2['gender'] = '女';
- var_dump($member1, $member2);
+ var_dump($member1, $member2);
- print "
";
- var_dump($member1, $member2);
- print "
";
-
-?>
\ No newline at end of file
+ echo '
';
+ var_dump($member1, $member2);
+ echo '
';
diff --git a/asial/member2.php b/asial/member2.php
index 234369d..9037459 100644
--- a/asial/member2.php
+++ b/asial/member2.php
@@ -2,18 +2,16 @@
// 多次元配列テスト
- $member[1]['name'] = "アシアル太郎";
- $member[1]['age'] = 26;
- $member[1]['gender'] = "男";
+ $member[1]['name'] = 'アシアル太郎';
+ $member[1]['age'] = 26;
+ $member[1]['gender'] = '男';
- $member[2]['name'] = "アシアル花子";
- $member[2]['age'] = 28;
- $member[2]['gender'] = "女";
+ $member[2]['name'] = 'アシアル花子';
+ $member[2]['age'] = 28;
+ $member[2]['gender'] = '女';
- var_dump($member);
+ var_dump($member);
- print "
";
- var_dump($member);
- print "
";
-
-?>
\ No newline at end of file
+ echo '
';
+ var_dump($member);
+ echo '
';
diff --git a/asial/money.php b/asial/money.php
index 7dfd511..cb81c28 100644
--- a/asial/money.php
+++ b/asial/money.php
@@ -5,21 +5,20 @@
//$money = 1314;
$money = $_GET['money'];
-$kinds = array(1,5,10,50,100,1000,10000);
+$kinds = [1, 5, 10, 50, 100, 1000, 10000];
rsort($kinds);
foreach ($kinds as $val) {
- $quantity = floor($money / $val);
+ $quantity = floor($money / $val);
- if ($quantity == 0) {
- continue;
- }
+ if ($quantity == 0) {
+ continue;
+ }
- $money = $money - $val * $quantity;
+ $money = $money - $val * $quantity;
- print $val . "が" . $quantity . "枚
";
+ echo $val.'が'.$quantity.'枚
';
}
// print $val;
// print $money;
-
diff --git a/asial/phpinfo.php b/asial/phpinfo.php
index d6e4841..90154cc 100644
--- a/asial/phpinfo.php
+++ b/asial/phpinfo.php
@@ -1,5 +1,3 @@
\ No newline at end of file
+ phpinfo();
diff --git a/asial/uranai.php b/asial/uranai.php
index 2ee3ec9..8cc71bc 100644
--- a/asial/uranai.php
+++ b/asial/uranai.php
@@ -7,18 +7,18 @@
diff --git a/asial/variable.php b/asial/variable.php
index 703b4ec..4c8a158 100644
--- a/asial/variable.php
+++ b/asial/variable.php
@@ -6,26 +6,26 @@
";
- print "$apple_price 円のリンゴを $quantity 個買った場合の合計金額は $total_price 円です
";
+ // ダブルクォート内での変数展開
+ echo 'ダブルクォートの展開
';
+ echo "$apple_price 円のリンゴを $quantity 個買った場合の合計金額は $total_price 円です
";
- // ダブルクォート内での変数展開
- print "シングルクォートの展開
";
- print '$apple_price 円のリンゴを $quantity 個買った場合の合計金額は $total_price 円です
';
+ // ダブルクォート内での変数展開
+ echo 'シングルクォートの展開
';
+ echo '$apple_price 円のリンゴを $quantity 個買った場合の合計金額は $total_price 円です
';
- // ブレースでくくる場合
- print "変数名をブレースでくくった場合
";
- print "${apple_price}円のリンゴを${quantity}個買った場合の合計金額は${total_price}円です
";
+ // ブレースでくくる場合
+ echo '変数名をブレースでくくった場合
';
+ echo "${apple_price}円のリンゴを${quantity}個買った場合の合計金額は${total_price}円です
";
- // 表示を分割
- print "表示を分割
";
- print $apple_price . "円のリンゴを" . $quantity . "個買った場合の合計金額は" . $total_price . "円です
";
+ // 表示を分割
+ echo '表示を分割
';
+ echo $apple_price.'円のリンゴを'.$quantity.'個買った場合の合計金額は'.$total_price.'円です
';
?>
diff --git a/asial/while.php b/asial/while.php
index 668b06e..a8dc7f4 100644
--- a/asial/while.php
+++ b/asial/while.php
@@ -2,17 +2,14 @@
// while分テスト
- $i = 1;
+ $i = 1;
- while ($i <= 31) {
+ while ($i <= 31) {
+ echo "$i";
- print "$i";
+ if ($i % 7 == 0) {
+ echo '
';
+ }
- if ($i % 7 == 0) {
- print "
";
- }
-
- $i = $i + 1;
- }
-
-?>
\ No newline at end of file
+ $i = $i + 1;
+ }
diff --git a/sns_php_v2/functions.php b/sns_php_v2/functions.php
index 391e6de..b4ddeee 100644
--- a/sns_php_v2/functions.php
+++ b/sns_php_v2/functions.php
@@ -1,38 +1,45 @@
getMessage();
- exit;
- }
+function connectDb()
+{
+ try {
+ return new PDO(DNS, DB_USER, DB_PASSWORD);
+ } catch (PDOException $e) {
+ echo $e->getMessage();
+ exit;
+ }
}
-function h($s) {
- return htmlspecialchars($s, ENT_QUOTES, "UTF-8");
+function h($s)
+{
+ return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
}
-function setToken() {
- $token = sha1(uniqid(mt_rand(), true));
- $_SESSION['token'] = $token;
+function setToken()
+{
+ $token = sha1(uniqid(mt_rand(), true));
+ $_SESSION['token'] = $token;
}
-function checkToken() {
- if (empty($_SESSION['token']) || ($_SESSION['token'] != $_POST['token'])) {
- echo "不正な処理が行われました。";
- exit;
- }
+function checkToken()
+{
+ if (empty($_SESSION['token']) || ($_SESSION['token'] != $_POST['token'])) {
+ echo '不正な処理が行われました。';
+ exit;
+ }
}
-function emailExists($email, $dbh) {
- $sql = "select * from users where email = :email limit 1";
- $stmt = $dbh->prepare($sql);
- $stmt->execute(array(":email" => $email));
- $user = $stmt->fetch();
- return $user ? true : false;
+function emailExists($email, $dbh)
+{
+ $sql = 'select * from users where email = :email limit 1';
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([':email' => $email]);
+ $user = $stmt->fetch();
+
+ return $user ? true : false;
}
-function getSha1Password($s) {
- return (sha1(PASSWORD_KEY.$s));
+function getSha1Password($s)
+{
+ return sha1(PASSWORD_KEY.$s);
}
diff --git a/sns_php_v2/index.php b/sns_php_v2/index.php
index 38f299e..ea58662 100644
--- a/sns_php_v2/index.php
+++ b/sns_php_v2/index.php
@@ -1,23 +1,23 @@
query($sql) as $row) {
- array_push($users, $row);
+ array_push($users, $row);
}
?>
diff --git a/sns_php_v2/login.php b/sns_php_v2/login.php
index c05062f..f2bec30 100644
--- a/sns_php_v2/login.php
+++ b/sns_php_v2/login.php
@@ -1,73 +1,72 @@
prepare($sql);
- $stmt->execute(array(":email" => $email, ":password" => getSha1Password($password)));
- $user = $stmt->fetch();
- return $user ? $user : false;
+function getUser($email, $password, $dbh)
+{
+ $sql = 'select * from users where email = :email and password = :password limit 1';
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([':email' => $email, ':password' => getSha1Password($password)]);
+ $user = $stmt->fetch();
+
+ return $user ? $user : false;
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- // CSRF対策
- setToken();
-} else {
- checkToken();
-
- $email = $_POST['email'];
- $password = $_POST['password'];
-
- $dbh = connectDb();
-
- $err = array();
-
- // メールアドレスが登録されていない
- if (!emailExists($email, $dbh)) {
- $err['email'] = 'このメールアドレスは登録されていません';
- }
-
- // メールアドレスの形式不正
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $err['email'] = 'メールアドレスの形式が正しくありません';
- }
-
- // メールアドレスが空
- if ($email == '') {
- $err['email'] = 'メールを入力してください';
- }
-
- // メールアドレスとパスワードが正しくない
- $me = getUser($email, $password, $dbh);
- if (!$me) {
- $err['password'] = "パスワードとメールアドレスが正しくありません";
- }
-
-
- // パスワードが空?
- if ($password == '') {
- $err['password'] = 'パスワードを入力してください';
- }
-
- // エラーチェック
- if (empty($err)) {
- // セッションハイジャック対策
- session_regenerate_id(true);
- $_SESSION['me'] = $me;
- header('Location: '.SITE_URL);
- exit;
- }
-
-
+ // CSRF対策
+ setToken();
+} else {
+ checkToken();
+
+ $email = $_POST['email'];
+ $password = $_POST['password'];
+
+ $dbh = connectDb();
+
+ $err = [];
+
+ // メールアドレスが登録されていない
+ if (!emailExists($email, $dbh)) {
+ $err['email'] = 'このメールアドレスは登録されていません';
+ }
+
+ // メールアドレスの形式不正
+ if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ $err['email'] = 'メールアドレスの形式が正しくありません';
+ }
+
+ // メールアドレスが空
+ if ($email == '') {
+ $err['email'] = 'メールを入力してください';
+ }
+
+ // メールアドレスとパスワードが正しくない
+ $me = getUser($email, $password, $dbh);
+ if (!$me) {
+ $err['password'] = 'パスワードとメールアドレスが正しくありません';
+ }
+
+ // パスワードが空?
+ if ($password == '') {
+ $err['password'] = 'パスワードを入力してください';
+ }
+
+ // エラーチェック
+ if (empty($err)) {
+ // セッションハイジャック対策
+ session_regenerate_id(true);
+ $_SESSION['me'] = $me;
+ header('Location: '.SITE_URL);
+ exit;
+ }
}
?>
diff --git a/sns_php_v2/logout.php b/sns_php_v2/logout.php
index e7d51b7..f14232e 100644
--- a/sns_php_v2/logout.php
+++ b/sns_php_v2/logout.php
@@ -1,18 +1,16 @@
prepare($sql);
-$stmt->execute(array(":id" => (int)$_GET[id]));
+$stmt->execute([':id' => (int) $_GET[id]]);
$user = $stmt->fetch();
if (!$user) {
- echo "no such user!";
- exit;
+ echo 'no such user!';
+ exit;
}
?>
diff --git a/sns_php_v2/signup.php b/sns_php_v2/signup.php
index eb717d1..6343037 100644
--- a/sns_php_v2/signup.php
+++ b/sns_php_v2/signup.php
@@ -1,70 +1,66 @@
prepare($sql);
- $params = array(
- ":name" => $name,
- ":email" => $email,
- ":password" => getSha1Password($password)
- );
- $stmt->execute($params);
- header('Location: '.SITE_URL.'login.php');
- exit;
- }
-
-
+ (:name, :email, :password, now(), now())';
+ $stmt = $dbh->prepare($sql);
+ $params = [
+ ':name' => $name,
+ ':email' => $email,
+ ':password' => getSha1Password($password),
+ ];
+ $stmt->execute($params);
+ header('Location: '.SITE_URL.'login.php');
+ exit;
+ }
}
-
-
?>
diff --git a/tests/FooTest.php b/tests/FooTest.php
index e33d233..3f2d322 100644
--- a/tests/FooTest.php
+++ b/tests/FooTest.php
@@ -1,11 +1,15 @@
assertTrue(true);
- $this->assertFalse(False);
- }
-
- public function testFooEquals(){
- $this->assertEquals('bar', 'bar');
- }
+
+class FooTest extends PHPUnit_Framework_TestCase
+{
+ public function testFoo()
+ {
+ $this->assertTrue(true);
+ $this->assertFalse(false);
+ }
+
+ public function testFooEquals()
+ {
+ $this->assertEquals('bar', 'bar');
+ }
}
diff --git a/time.php b/time.php
index 3fac261..6fc3cda 100644
--- a/time.php
+++ b/time.php
@@ -8,7 +8,3 @@
date_default_timezone_set('Asia/Tokyo');
$now = date('Y-m-d H:i:s');
echo $now;
-
-
-
-