2012-09-21 5 views
1

가능한 중복은 :
Headers already sent by PHPPHP 헤더를 사용하여 로그 아웃 페이지에 리디렉션()

나는 그래서이 같은 시도 일부 페이지로 리디렉션합니다.

www.example.com/logout.php?redirect=www.index-page.com/index.php 
     echo $redirect = "'Location: http://".$_GET['redirect']."'"; 
     //redirects to index 
     header($redirect); 

하지만 저에게는 효과가 없습니다. ther 제안입니다. 하지가 Warning: Cannot modify header information - headers already sent by

$redirect = "Location: http://". $_GET['redirect']; 
    header($redirect); 
+0

기본 디버깅이 먼저 필요합니다. 오류를 기록 (및/또는 표시)하고 PHP를 봅니다. 오류 기록. 또한 중복 된 질문에 대해 더 많이 배우게됩니다. – hakre

답변

4

뭔가 :

로그 아웃 링크에서 : logout.php 페이지에서

<a href="http://www.example.com/logout.php?redirect=<?=urlencode('http://www.index-page.com/index.php')?>"> Logout </a> 

:

<? 
    // destroy session 
    header('location:'.urldecode($_GET['redirect'])); 
    die(); 
?> 
1

당신은 당신 만 사용할 수 있습니다 필요가 없습니다 redirectecho없이 :

header("Location: http://".$_GET['redirect']); 
2

당신이 헤더 전에 echo을 사용할 수 없습니다

0

을 생성 할 경우 추가 '

$redirect = "Location: http://".$_GET['redirect']; 
0

문제가 여기에 있습니다

echo $redirect = "'Location: http://".$_GET['redirect']."'"; 
//redirects to index 
header($redirect); 

헤더 앞에 echo를 사용하지 않아도됩니다. header already sent 경고가 발생합니다.

여기이

$redirect = "Location: http://".$_GET['redirect']; 
//redirects to index 
header($redirect); 
1

처럼 사용하기가 함수

function redirectUser($link){ 
    header("location: $link"); 
} 

할 수있는 Google

$link='http://Google.com'; 
header("location: $link"); 

를 사용자를 리디렉션하는 예입니다 그리고 당신은 그것을 호출 할 수 있습니다 like

redirectUser('http://google.com'); 

또는

echo redirectUser('http://google.com'); 

것이다 일이 없음 오류!

나는 당신이오고 코드를 중단, 리디렉션 코드 후 die();를 사용하는 조언이 같은