<?php
$userid = $_POST["userid"];
$pword = $_POST["pword"];
# session
session_start();
# check that session is valid and set
if(!isset($_SESSION['login']))
{
header('Location: login.php');
}
# check that the required values have been entered
$testin1 = ($userid);
$testin2 = ($pword);
if($testin1 == "")
{
print "<hr><h1> No Username Entered, Please return to the Login page</h1></hr>";
}
elseif ($testin2 == "")
{
print "<hr><h1> No Password Entered, Please return to the Login page</h1></hr>";
}
# Connect to database
$connect = mysql_connect ("localhost","root") or die("Error Connecting to SQLServer");
$db = mysql_select_db ("test");
# query
$query = mysql_query ("select username from login where username = '$userid' and pword = '$pword';");
if($query === FALSE)
{
die(mysql_error());
}
$result = mysql_fetch_array($query);
$record = $result['username'] ;
if ($record != null)
# check if session is operational, if so redirect the user to the correct page
{
$_SESSION['login'] = true;
header('Location: index.php') ;
}
else if ($record == null)
{
header('Location: login.php');
}
?>
어디에서 작동하지 않는지 알고 계십니까? 'error free'인 것처럼 보이지만 index.php 페이지와 반대로 login.php 페이지로 다시 리디렉션됩니다. PHP에서 상대적인 초보자로서 도움이 될 것입니다. 당신은 키에 의해 결과를 액세스하기 위해 mysql_fetch_array().
를 사용하는PHP가 데이터베이스에 데이터를 등록하고 있지 않습니다.
감사
일부 인쇄 문을 넣었을 때 오류가 발생한 부분을 정확히 찾아 내면 로그인 할 때 무슨 일이 일어나는지 정확히 알 수 있습니다. – ajon
세션 변수가 확실합니까? 설정되어 있습니까? echo $ _SESSION [ 'login '] 그리고 설정되어 있는지 확인하십시오. – Wearybands
mysql_ * 함수를 사용하지 마십시오. 더 이상 사용되지 않습니다. 대신에 mysqli 나 PDO를 사용하라. 그러나, 당신은'if (! isset ($ _ SESSION [ 'login'])) {header ('Location : login.php'); }'index.php의 시작 부분에 표시됩니다. 즉,이 세션 속성이 설정되어 있지 않기 때문에 항상 리디렉션됩니다. – shadyyx