2013-11-03 2 views
0

약 100 번 훑어보고 페이지가 리디렉션되지 않는 이유를 찾을 수 없습니다. 공백이나 누락 된 출력을 찾을 수 없습니다. 누구든지 문제를 발견 할 수 있습니까? 여기로그인 후 내 페이지가 리디렉션되지 않는 이유는 무엇입니까?

function redirect_to($new_location) { 
     header("Location: " . $new_location); 
     exit; 
    } 

유효성 검사 기능은 다음과 같습니다 : 여기

<?php 
include_once('includes/sessions.php'); 
include_once('connections/localhost.php'); 
include_once('includes/functions.php'); 
include_once('includes/validations.php'); 
?> 
<?php 
$username = ""; 
if (isset($_POST['submit'])) { 
    $required_fields = array("username", "password"); 
    validate_there($required_fields); 
    if (empty($errors)) { 
     $username = $_POST["username"]; 
     $password = $_POST["password"]; 
     $found_user = attempt_login($username, $password); 
    if ($found_user) { 
    $_SESSION["user_id"] = $found_user["user_id"]; 
    $_SESSION["username"] = $found_user["username"]; 
    redirect_to("index.php");  
    } else { 
     $_SESSION["message"] = "Username/password not found."; 
    } 
    } 
} else { 
} 
?> 

가 방향 전환하는 기능입니다 : 여기

내 코드입니다

$errors = array(); 

function fieldname_is_text($fieldname) { 
    $fieldname = str_replace("_", " ", $fieldname); 
    $fieldname = ucfirst($fieldname); 
    return $fieldname; 
} 


function has_presence($value) { 
    return isset($value) && $value !== ""; 
} 

function validate_there($required_fields) { 
    global $errors; 
    foreach($required_fields as $field) { 
    $value = trim($_POST[$field]); 
    if (!has_presence($value)) { 
     $errors[$field] = fieldname_is_text($field) . " can't be blank"; 
    } 
    } 
} 
+0

어떤 오류가 발생합니까? –

+0

중요한 것은 아니지만 PHP 인클로저를 닫은 다음 다시 열어 보는 이유는 무엇입니까? (예 :'?> hargobind

+0

'$ found_user' 및'validate_there'에 대한 코드를 게시하십시오. –

답변

1

당신은 (모든 출력이 가장 가능성 HTML 또는 오류 메시지). 출력을 보내기 전에 모든 헤더를 보내야합니다.

일부 출력은 볼 수 없지만 있습니다. 공백 등을 제거하십시오.

?> 
<?php 
+0

그래, 어디서? 출력을 켜면 출력이나 오류 메시지가 표시되지 않습니다. – SherwoodPro

+0

@SherwoodPro'?>

+0

의 출력이 있습니다. 포함 된 파일도 확인하십시오. 그들이 PHP 만 포함하는 것이라면 파일의 끝 부분에있는?>를 제거하는 것이 안전합니다. 이렇게하면 나중에 공백이 브라우저로 전송되지 않습니다. 닫기 태그를 건너 뛰는 것이 좋은 코딩 방법인지 여부에 대한 몇 가지 토론이 있지만 유효한 내용입니다. –

0

리다이렉션을 위해이 기능을 사용해보십시오.

<?php 
function redirect_to($new_location) 
{ 
    ?> 
<script type="text/javascript"> 
    window.location = '<?php echo $new_location;?>'; 
</script> 
<?php 
} 

?> 
+0

나는 이것을 받아 들일 수 없습니다. 방금 빈 페이지를주었습니다. 그래도 고마워. :) – SherwoodPro

+0

함수에서 값을 전달하고 변수에 값 (페이지 경로), $ new_location ...이 있어야합니다. – Zeeshan

관련 문제