0
3 개의 파일이 있습니다. login.php
에서 (loginFunctions.php
, login.php
, index.php
) , 내가 값을 가지고 값을 확인하고 login.php
로 돌아 준비된 명령문에서 userID
을 선택 loginFunction.php
에 전달합니다. 그런 다음 login.php
은 (get('value'))
이라는 메서드를 호출하여 userID
을 전달하고 사용자 정보를 반환합니다. 나는 로그인과 색인 페이지에서 세션을 시작했다. 세션에 저장된 정보를 반향하려고했지만 아무것도 반환하지 않았습니다.
내 코드 :
loginFunction.php
<?php
function absolute_url($page = 'index.php') {
//header('Location: http:\\localhost');
//exit(); //terminates the script
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
$url = rtrim($url, '/\\');
$url .= '/' . $page;
return $url;
}
function checkLogin($email = '', $password = '') {
$errors = array();
if (empty($email)){
$errors[] = 'You must enter your email';
}
if (empty($password)){
$errors[] = 'You must enter a password';
}
if (empty($errors)) {
////set up database econnection
require_once 'DO_Classes/mysqli_connect.php';
$db = new Database();
$dbc = $db->getConnection();
$stmt = $dbc->prepare("SELECT user_ID FROM User WHERE user_email=? AND AES_DECRYPT(user_password, 'p0ly')=?");
if ($stmt) {
$stmt->bind_param('ss', $email, $password);
if ($stmt->execute()) {
$stmt->store_result();
$stmt->bind_result($user_ID);
$stmt->fetch();
$stmt->close();
if(!empty($user_ID)){
return array(true, $user_ID);
}else{
/*
* <div class=\"alert alert-success alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>
Invalid email or password
</div>
*/
$errors[] = '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<p align="center">Invalid email or password</p>
</div>';
}
} else {
$errors[] = 'Passwords do not match';
}
}else {
echo '<p class="error"> Oh dear. There was a databse error</p>';
echo '<p class = "error">' . mysqli_error($stmt) . '</p>';
}
}
return array(false, $errors);
}
?>
login.php
<?php
if (isset($_POST['submitted'])) {
//require_once is similar to 'include' but ensures the code is not copied multiple times
require_once('Functions/loginFunctions.php');
//list() is a way of assigning multiple values at the same time
//checkLogin() function returns an array so list here assigns the values in the array to $check and $data
list($check, $data) = checkLogin($_POST['email'], $_POST['password']);
if ($check) {
//setcookie('FName', $data['FName'], time()+ 900) ; //cookie expires after 15 mins
//setcookie('LName', $data['LName'], time() + 900) ;
session_start();
require_once 'Classes/DO_Users.php';
$user = new DO_User();
$user->get($data);
//use session variables instead of cookies
//these variables should now be available to all pages in the application as long as the users session exists
$_SESSION['userID'] = $user->userID;
$_SESSION['userType'] = $user->userTypeID;
$_SESSION['last_activity'] = time(); //your last activity was now, having logged in.
$_SESSION['expire_time'] = 60 * 5; //expire time in seconds: three hours (you must change this)
//to enable $_SESSION array to be populated we always need to call start_session() - this is done in header.php
//print_r is will print out the contents of an array
//print_r($_SESSION);
//
//Redirect to another page
$url = absolute_url('index.php'); //function defined in Loginfunctions.php to give absolute path for required page
//this version of the header function is used to redirect to another page
header("Location: $url"); //since we have entered correct login details we are now being directed to the home page
exit();
} else {
$errors = $data;
}
}
if (!empty($errors)) {
//foreach is a simplified version of the 'for' loop
foreach ($errors as $err) {
echo "$err <br />";
}
echo '</p>';
}
//display the form
?>
는 index.php
, 나는 session_start();
을 가지고 있지만 아무것도 반환하지 않습니다 require_once 'header.php';
라고, 왜?
많은 답변이 아닙니다. 당신은 알지도 모르고 이해할 수있는 다른 사람들을 위해 자세히 설명해야합니다. 그렇지 않다면, 당신은 단지 대답/질문을 삭제해야합니다. –
@ Fred-ii- 준비된 명령문의 선언에 값이 없어서 준비된 명령문이 작동하지 않습니다. – imohd23
댓글이 아닌 답변에 바로 답을 포함시키는 것이 가장 좋습니다. 사용 된 구문을 포함하면 보너스가 추가됩니다. –