2012-02-21 6 views
0

제출할 때 로그인 양식이 있습니다. 다시 로그인 페이지로 리디렉션됩니다. 어떤 구문 오류도 찾을 수없는 것 같아서 로그인 양식에 필수적인 것을 빠뜨린 것 같습니다. 여기에 코드가 있습니다.로그인 양식 리디렉션 자체에 제출

login.php :

<? 
require ('../includes/config.inc.php'); 
if ($_POST['act'] == "Insert") { 
    #// Additional security check 
    $RR = mysql_query("SELECT id from BPLA_adminusers"); 
    if (mysql_num_rows($RR) > 0) { 
     print "Fatal error: user cannot be inserted - one or more administrators are already present in the database.<a href=login.php>login page</a>"; 
     exit ; 
    } 
    $md5_pass = md5($MD5_PREFIX . $_POST['password']); 
    echo $query = "insert into BPLA_adminusers values (10,'$_POST[username]', '$md5_pass', '20011224', '20020110093458', 1)"; 
    $result = @mysql_query($query); 
    #// Redirect 
    Header("Location: login.php"); 
    exit ; 
} 
$query = "select MAX(id) from BPLA_adminusers"; 
$result = @mysql_query($query); 
while ($row = mysql_fetch_row($result)) { 
    $id = $row[0] + 1; 
} 
?> 
<? 
if($id==1) { 
$id=0; 
?> 
<form name="login" data-ajax="false" action="login.php" method="post"> 
    <span><? print $ERR;?></span> 
    <label for="<? print "Username";?>"><? print "Username";?></label> 
    <input type="text" name="username" /> 
    <label for="<? print "Password";?>"><? print "Password";?></label> 
    <input type="password" name="password" /> 
    <input type="submit" name="action" value="<? echo $MSG_5204;?>"> 
</form> 
<? 
} else { 
$id=1; 
#// 
if($_POST[action] == "login") { 
if(strlen($_POST[username]) == 0 || strlen($_POST[password]) == 0) { 
$ERR = $ERR_047; 
} else { 
$query = "select * from BPLA_adminusers where username='$_POST[username]' and password='".md5($MD5_PREFIX.$_POST[password])."'"; 
$res = @mysql_query($query); 
if(!$res) { 
print "Error: $query<BR>".mysql_error(); 
exit; 
} 
if(mysql_num_rows($res) == 0) { 
$ERR = $ERR_048; 
} else { 
$admin = mysql_fetch_array($res); 
#// Set sessions vars 
$BPLowbidAuction_ADMIN_LOGIN = $admin[id]; 
$BPLowbidAuction_ADMIN_USER = $admin[username]; 
$_SESSION["BPLowbidAuction_ADMIN_LOGIN"]=$BPLowbidAuction_ADMIN_LOGIN; 
$_SESSION["BPLowbidAuction_ADMIN_USER"]=$BPLowbidAuction_ADMIN_USER; 
#// Update last login information for this user 
$query = "update BPLA_adminusers set lastlogin='".date("YmdHis")."' where username='$admin[username]'"; 
$rr = mysql_query($query); 
if(!$rr) { 
print "Error: $query<BR>".mysql_error(); 
exit; 
} 
#// Redirect 
print "<SCRIPT Language=Javascript> 
parent.location.href='index.php'; 
</SCRIPT>"; 
//Header("Location: home.php"); 
exit; 
} 
} 
} 
?> 
<? if(!$act || ($act && $ERR)) { 
?> 
<form name="login" data-ajax="false" action="login.php" method="post"> 
    <span><? print $ERR;?></span> 
    <label for="<? print "Username";?>"><? print "Username";?></label> 
    <input type="text" name=username /> 
    <label for="<? print "Password";?>"><? print "Password";?></label> 
    <INPUT TYPE=password name=password /> 
    <input type="submit" NAME="action" VALUE="login"> 
</form> 
<? }?> 
<? } 
    require("./footer.php"); 
?> 

이 코드는 index.php를 내에 배치되고 있으며이 제출 때 다시을 index.php로 리디렉션하는 경우/다른 문에 사용되고있다.

의 index.php :

<? 
require ('../includes/config.inc.php'); 
include ('bar.php'); 
if (!empty($_SESSION['BPLowbidAuction_ADMIN_LOGIN'])) { 
    include ('home.installation.php'); 
} else { 
    include ('login.php'); 
} 
?> 

문제는 로그인 양식이 처음 리디렉션 있다는 것이다 로그인 폼 코드가 표시됩니다 다시 "index.php에"로하고 "login.php"과에 것처럼 나는 결코 "bar.php"는 단지 머리말이며 페이지의 메뉴와 "home.installation.php"는 실제로 보여지기로되어있는 홈 페이지입니다.

+1

슬래시한다? – Deepak

+1

괜찮습니다. add session_start(); Deepak

+0

무엇인지 확실하지 않습니까 ?? – Deepak

답변

3
Header("Location: login.php"); 

Location 헤더는 절대 유효한 URI를 가리켜 야. 나는. 스키마 (http://)로 시작, 또는 앞으로 당신이 $ _SESSION 변수를 사용하기 전에으로 session_start()를 사용하는 /login.php

HTTP 1.1 RFC on Location

+0

팁 주셔서 감사합니다,하지만 그건 내 문제를 해결하지 못했습니다. 이제 코드를 헤더 ("Location : login.php");에서 헤더 ("위치 : http://www.luvbid.com/admin/login.php")로 변경했습니다. – Cary

+1

절대 경로 수 header()에서 사용되며 http : //로 시작하지 않아도됩니다. 세션 변수가 값을 저장하지 않는다고 생각합니다. config.inc.php에는 무엇이 포함되어 있습니까? – Deepak

+0

'parent.location.href = 'index.php'' 또한 절대 URI/경로를 요구할 수 있습니다. (절대 경로는 슬래시로 시작합니다.) – Vitamin