나는 커다란 죄를 짓고 일부 복사 및 붙여 넣기 프로그래밍을 수행했습니다. 내가 알지. 나쁜 프로그래머! 불행히도, 나는 PHP와 MySQL에 정통하지 못하다. (나는 그것을 치료하기 위해 몇 가지 Udemy 클래스에 등록 했음에도) 시스템에 로그인해야한다. 그래서 나는 here이라는 혀를 사용했습니다. 이제는 훌륭하게 작동하지만, 로그인 할 때 사용자 정의 페이지로 리디렉션 할 페이지가 필요합니다.특정 사용자 페이지로 리디렉션
끝으로 페이지라는 끝에 데이터베이스를 추가하고 각 사용자에게 필요한 전체 URL을 채우고 페이지 열의 값을 얻기 위해 코드를 변경하려고했습니다. PHP와 내가 온라인에서 찾은 것들에 대한 지식이 거의 없지만 리다이렉트를 위해 데이터베이스 컬럼 "page"에서 값을 얻는 것처럼 보일 수 없다. 그냥 빈 페이지를 보여줍니다. 여기
관련 될 것으로 보인다 코드입니다 :<?php
include_once 'db_connect.php';
include_once 'functions.php';
sec_session_start();
if (isset($_POST['email'], $_POST['p'])) {
$email = $_POST['email'];
$password = $_POST['p'];
if (login($email, $password, $mysqli) == true) {
// Login success
header('Location: ../selection.php');
exit();
} else {
// Login failed
header('Location: ../error.php?error=1');
}
} else {
// The correct POST variables were not sent to this page.
echo 'Invalid Request';
}
와 (나는이 관련이 경우 실제로는 잘 모르겠지만, 나는 누군가가 내가 할 수있는 경우 튜토리얼로 이동하고 싶지 않았다
<?php
include_once 'psl-config.php';
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = SECURE;
// This stops JavaScript being able to access the session id.
$httponly = true;
// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}
// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
// Sets the session name to the one set above.
session_name($session_name);
session_start(); // Start the PHP session
session_regenerate_id(); // regenerated the session, delete the old one.
}
function login($email, $password, $mysqli) {
// Using prepared statements means that SQL injection is not possible.
if ($stmt = $mysqli->prepare("SELECT id, username, password, salt
FROM members
WHERE email = ?
LIMIT 1")) {
$stmt->bind_param('s', $email); // Bind "$email" to parameter.
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
// get variables from result.
$stmt->bind_result($user_id, $username, $db_password, $salt);
$stmt->fetch();
// hash the password with the unique salt.
$password = hash('sha512', $password . $salt);
if ($stmt->num_rows == 1) {
// If the user exists we check if the account is locked
// from too many login attempts
if (checkbrute($user_id, $mysqli) == true) {
// Account is locked
// Send an email to user saying their account is locked
return false;
} else {
// Check if the password in the database matches
// the password the user submitted.
if ($db_password == $password) {
// Password is correct!
// Get the user-agent string of the user.
$user_browser = $_SERVER['HTTP_USER_AGENT'];
// XSS protection as we might print this value
$user_id = preg_replace("/[^0-9]+/", "", $user_id);
$_SESSION['user_id'] = $user_id;
// XSS protection as we might print this value
$username = preg_replace("/[^a-zA-Z0-9_\-]+/",
"",
$username);
$_SESSION['username'] = $username;
$_SESSION['login_string'] = hash('sha512',
$password . $user_browser);
// Login successful.
return true;
} else {
// Password is not correct
// We record this attempt in the database
$now = time();
$mysqli->query("INSERT INTO login_attempts(user_id, time)
VALUES ('$user_id', '$now')");
return false;
}
}
} else {
// No user exists.
return false;
}
}
}
function checkbrute($user_id, $mysqli) {
// Get timestamp of current time
$now = time();
// All login attempts are counted from the past 2 hours.
$valid_attempts = $now - (2 * 60 * 60);
if ($stmt = $mysqli->prepare("SELECT time
FROM login_attempts
WHERE user_id = ?
AND time > '$valid_attempts'")) {
$stmt->bind_param('i', $user_id);
// Execute the prepared query.
$stmt->execute();
$stmt->store_result();
// If there have been more than 5 failed logins
if ($stmt->num_rows > 5) {
return true;
} else {
return false;
}
}
}
function login_check($mysqli) {
// Check if all session variables are set
if (isset($_SESSION['user_id'],
$_SESSION['username'],
$_SESSION['login_string'])) {
$user_id = $_SESSION['user_id'];
$login_string = $_SESSION['login_string'];
$username = $_SESSION['username'];
// Get the user-agent string of the user.
$user_browser = $_SERVER['HTTP_USER_AGENT'];
if ($stmt = $mysqli->prepare("SELECT password
FROM members
WHERE id = ? LIMIT 1")) {
// Bind "$user_id" to parameter.
$stmt->bind_param('i', $user_id);
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
if ($stmt->num_rows == 1) {
// If the user exists get variables from result.
$stmt->bind_result($password);
$stmt->fetch();
$login_check = hash('sha512', $password . $user_browser);
if ($login_check == $login_string) {
// Logged In!!!!
return true;
} else {
// Not logged in
return false;
}
} else {
// Not logged in
return false;
}
} else {
// Not logged in
return false;
}
} else {
// Not logged in
return false;
}
}
function esc_url($url) {
if ('' == $url) {
return $url;
}
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
$strip = array('%0d', '%0a', '%0D', '%0A');
$url = (string) $url;
$count = 1;
while ($count) {
$url = str_replace($strip, '', $url, $count);
}
$url = str_replace(';//', '://', $url);
$url = htmlentities($url);
$url = str_replace('&', '&', $url);
$url = str_replace("'", ''', $url);
if ($url[0] !== '/') {
// We're only interested in relative links from $_SERVER['PHP_SELF']
return '';
} else {
return $url;
}
}
)을 방지 나는 PHP.net 워드 프로세서를 쳐다 보면서, 나는 온라인으로 볼 몇 가지 솔루션을 시도했지만, 내가 찾은 아무것도 작동하는 것 같다. 이 기능을 만들어야합니까? PHP와 MySQL에 대한 기본적인 지식이 필요하다는 것을 알고 있습니다.
자세한 정보가 필요하면 알려주세요.
감사합니다.
여기서 DB에서 페이지를 가져 오려고하는 부분은 어디입니까? – webeno
빈 페이지는 일반적으로 코드에 문제가 있음을 의미하며, 세부 정보는 서버 오류 로그에 기록됩니다. 거기서 시작하십시오. –
나는 많은 다른 것들을 시도했으며, 나는 단지 원래의 코드와 함께 갔다. 나는 내가 이미 실패했음을 알지만 코드의 힙을 피하려고 노력했다. 나는 몇 가지 시도를하기 위해 질문을 수정해야 하는가? –