質問編集履歴

1

どこで$_SESSIONの値を入れているかを示すコードを追記致しました。

2020/06/10 01:51

投稿

Anstrengung
Anstrengung

スコア3

test CHANGED
File without changes
test CHANGED
@@ -18,14 +18,94 @@
18
18
 
19
19
  ### 該当のソースコード
20
20
 
21
-
22
-
23
- ```PhP
21
+ ```PHP
24
22
 
25
23
  <?php
26
24
 
25
+ session_start();
26
+
27
27
  require('dbconnect.php');
28
28
 
29
+ header('Expires:-1');
30
+
31
+ header('Cache-Control:');
32
+
33
+ header('Pragma:');
34
+
35
+
36
+
37
+ if ($_COOKIE['email']!== ''){
38
+
39
+ $email = $_COOKIE['email'];
40
+
41
+ }
42
+
43
+
44
+
45
+
46
+
47
+ if(!empty($_POST)){
48
+
49
+ $email = $_POST['email'];
50
+
51
+ if($_POST["email"]!==''&&$_POST["password"]!==''){
52
+
53
+ $login = $db->prepare('SELECT * FROM users WHERE email=? AND password=?');
54
+
55
+ $login->execute(array(
56
+
57
+ $_POST["email"],
58
+
59
+ sha1($_POST["password"])
60
+
61
+ ));
62
+
63
+ $user =$login->fetch();
64
+
65
+
66
+
67
+ if($user){//こちらです
68
+
69
+ $_SESSION['id'] = $user['id'];
70
+
71
+ $_SESSION['time'] = time();
72
+
73
+
74
+
75
+ if ($_POST['save'] === 'on'){
76
+
77
+ setcookie('email',$_POST['email'],time()+60*60*24*14);
78
+
79
+ }
80
+
81
+ header('Location:index.php');
82
+
83
+ exit();
84
+
85
+ }else{
86
+
87
+ $error['login'] = 'failed';
88
+
89
+ }
90
+
91
+ }else{
92
+
93
+ $error['login'] = 'blank';
94
+
95
+ }
96
+
97
+ }
98
+
99
+ ```
100
+
101
+
102
+
103
+ ```PHP
104
+
105
+ <?php
106
+
107
+ require('dbconnect.php');
108
+
29
109
  session_start();
30
110
 
31
111