개발! 딱 깔끔하고 센스있게!

PHP 헤더 리디렉션이 작동하지 않음 [중복] 본문

개발 스크랩 메모/PHP

PHP 헤더 리디렉션이 작동하지 않음 [중복]

렉사이 2020. 12. 18. 23:55

This question already has an answer here:

include('header.php'); $name = $_POST['name']; $score = $_POST['score']; $dept = $_POST['dept']; $MyDB->prep("INSERT INTO demo (`id`,`name`,`score`,`dept`, `date`) VALUES ('','$name','$score','$dept','$date')"); // Bind a value to our :id hook // Produces: SELECT * FROM demo_table WHERE id = '23' $MyDB->bind(':date', $date); // Run the query $MyDB->run(); header('Location:index.php'); exit; 

위쪽 코드가 줄곧 나에게 중점을 주었다.

오류가 다음과 같습니다:

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/testygubbins/OO/test/header.php:15) in /Applications/MAMP/htdocs/testygubbins/OO/test/form.php on line 16.

나는 이것에 완전히 헷갈렸다.

제가 어떻게 해야 성공할 수 있는지 아시는 분이 계세요?

편집

header.php 코드:

                                                  
                

                
                
                  Test 
                

                
                













                
                  

대답

당신의 수신자 를 자세히 살펴보세요 ——아마도 당신은 편지를 받은 후에 공행이 하나 있습니까?>>

이것은 일부 텍스트 공백을 출력으로 발송해 후속 호출을 막을 것이다.

주의, 마감가를 떠나는 것은 합법적인 것입니까?>> include 파일을 닫는 것은 이 문제의 유용한 습관 용법입니다.

(편집: 출력 제목을 확인하려면, 어떤 html 출력을 수행하거나 출력 완충을 사용하여 포착해야 합니다.

마지막으로 header php 설명서 페이지가 제시한 바와 같이 전체 url 을 사용하십시오:

Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

Comments