2017-02-25 4 views
-1

로그인 페이지에 문제가 있습니다. 로그인 버튼을 누를 때 나를 기억하기 확인란이 선택되어있을 때만 사용자 패널로 이동합니다. 확인되지 않으면 로그인 페이지에 그대로 있습니다. 나는 오류를 알아낼 수 없다.로그인 페이지 오류

include("Database/database.php"); 
session_start(); 
if(isset($_COOKIE['username']) and isset($_COOKIE['passcode'])) { 
    $username = $_COOKIE['username']; 
    $passcode = $_COOKIE['passcode']; 

    $_SESSION['name'] = $username; 
    $_SESSION['pwd'] = $passcode; 

    header("Location: useraccount.php"); /*Checks if cookies are set then takes me directly to useraccount.php */ 

    } else if (isset($_POST['login'])) { 
     $username = $_POST['username']; 
     $userpwd = $_POST['userpwd']; 
     $rem = $_POST['remember']; 

     $query = "SELECT * FROM login WHERE userName = '$username' AND Password = '$userpwd'"; 

     $result = mysqli_query($link, $query); 
     $row = mysqli_num_rows($result); 

     if ($row > 0) { 
      $_SESSION['name'] = $username; 
      $_SESSION['pwd'] = $userpwd; 

      if (isset($_POST['remember']))  /*if remember me checkbox is checked than it set cookies and it takes me to useraccount.php page. But if I donot check the check box (remember me) than I am where I am on login page. */ 
      { 
       setcookie("username", $username, time()+60*60*7); 
       setcookie("passcode", $userpwd, time()+60*60*7); 
      } 

      header("Location: useraccount.php");  /* It should procees to    useracocunt.php page but it stays on login.php*/ 
     } else { 
      header("Location: login.php");  /*Used this for testing purpose if login fails it takes me to homepage which is working fine*/ 
     } 
     mysqli_close($link); 

    } 
} 

답변

1

이 문제에 대한 해결책을 찾았습니다. 쿠키를 설정하지 않은 경우 헤더를 다시 로그인 페이지로 리디렉션하는 것이 모두 실수였습니다.

  • 그래서 당신은 당신이 적절한 위치에 해당 파일에 대한 "URL"또는
  • 일부 철자 실수가 있어야 그것을 향하고 있는지 확인 헤더와 관련된 문제에 직면하는 경우.
0

뺨에 if 문을 세션에 저장합니다. 세션을 추가하기는하지만 아무 것도 확인하지 않습니다.

<?php 
     include("Database/database.php"); 
     session_start(); 

     if(isset($_COOKIE['username']) and isset($_COOKIE['passcode'])) 
     { 
      $username = $_COOKIE['username']; 
      $passcode = $_COOKIE['passcode']; 

      $_SESSION['name'] = $username; 
      $_SESSION['pwd'] = $passcode; 

      header("Location: useraccount.php"); /*Checks if cookies are set then takes me directly to useraccount.php */ 

     } 

     else if(isset($_POST['login'])) 
     { 
      $username = $_POST['username']; 
      $userpwd = $_POST['userpwd']; 
      $rem = $_POST['remember']; 

      $query = "SELECT * FROM login WHERE userName = '$username' AND Password = '$userpwd'"; 

      $result = mysqli_query($link, $query); 
      $row = mysqli_num_rows($result); 

      if($row > 0) 
      { 
       $_SESSION['name'] = $username; 
       $_SESSION['pwd'] = $userpwd; 

       if (isset($_POST['remember']))  /*if remember me checkbox is checked than it set cookies and it takes me to useraccount.php page. But if I donot check the check box (remember me) than I am where I am on login page. */ 
       { 
        setcookie("username", $username, time()+60*60*7); 
        setcookie("passcode", $userpwd, time()+60*60*7); 
       } 

       header("Location: useraccount.php");  /* It should procees to    useracocunt.php page but it stays on login.php*/ 
      } 

      else 
      { 
       header("Location: login.php");  /*Used this for testing purpose if login fails it takes me to homepage which is working fine*/ 
      } 
      mysqli_close($link); 

     } if (isset($_SESSION['name']) and isset($_SESSION['pwd'])){ 

header("Location: useraccount.php");  /* It should procees to    useracocunt.php page but it stays on login.php*/ 

} 

     ?> 
+0

안녕하세요, 이전에 해 보았습니다. 도움이되지 않습니다. 사용자가 쿠키를 확인한 경우 기억할 때 표시됩니다. 여전히 자신의 계정에 로그인되어 있어야합니다. –

+0

세션을 확인하기위한 if 문을 추가하여 누락되었습니다. 이것을 추가하십시오. –

+0

하지만 useraccount.php에서 쿠키뿐만 아니라 세션도 확인하십시오 .. –

1

동일한 문제가 발생하는 데 도움이되었습니다. 로그인 후 동일한 로그인 페이지로 리디렉션했습니다. 내 쿠키 조건을 올바르게 설정하지 않았 음