programing

경고: session_start(): 세션 쿠키를 보낼 수 없음 - 헤더는 이미 에 의해 전송되었습니다(출력 시작 시간:

telebox 2023. 10. 14. 10:04
반응형

경고: session_start(): 세션 쿠키를 보낼 수 없음 - 헤더는 이미 에 의해 전송되었습니다(출력 시작 시간:

로그인 페이지에 다음과 같은 경고가 표시됩니다.로컬 호스트에서는 작동하지만 원격 호스트에서는 작동하지 않음

경고: session_start() [function.세션 시작]:세션 쿠키를 보낼 수 없음 - 이미 보낸 헤더(출력은 8행에서 시작됨)

경고: session_start() [function.세션 시작]:세션 캐시 제한기를 전송할 수 없음 - 헤더가 이미 전송되었습니다(출력은 8행에서 시작됨).

enter image description here

색인을 보다

<?php
session_start();
if(isset($_SESSION['usr']) && isset($_SESSION['pswd'])){
header('Location: content.php');}
?>
<body>
<center>
<form method='post' action='login.php'>
<!– in this example I link it with login.php to check the password & username–>
<table>
<tr><td>Username:</td><td><input type='text' name='usr'></td></tr>
<tr><td>Password:</td><td><input type='password' name='pswd'></td>
</tr>
<tr><td><input type='submit' name='login' value='Login'></td>
<td><input type='reset' name='reset' value='Reset'></td></tr>
</table>
</form>
</center>
</body>  

만족할 만한php

<body>
<a href="resumedownload.php">Click here to Download to Resume</a>
<?php
session_start();
if(!isset($_SESSION["usr"]) || !isset($_SESSION["pswd"])){
 header('Location: index.php');}
include 'logoff.php';
?>
</body>

로그인 합니다.

<body>
<?php
session_start();
if($_REQUEST['usr']=='suman.trytek' && $_REQUEST['pswd']=='solutions'){
$_SESSION['usr'] = 'suman.trytek';
$_SESSION['pswd'] = 'solutions';
header('Location: content.php');
}
else{
header('Location: index.php');
}
?>
</body>

이동합니다.session_start();항상 페이지의 맨 위에 있습니다.

<?php
@ob_start();
session_start();
?>
  1. session_start ()이(가) 소스 상단에 있어야 합니다. html이나 기타 출력은 없습니다!
  2. session_start ()를 한 번만 보낼 수 있습니다.
  3. 이참에if(session_status()!=PHP_SESSION_ACTIVE) session_start()

버퍼를 부분적으로 이미 전송한 경우에는 session_start()을(를) 사용할 수 없습니다.

즉, 스크립트가 이미 클라이언트에 정보(원하는 정보 또는 오류 보고서)를 보낸 경우 session_start()가 실패합니다.

언급URL : https://stackoverflow.com/questions/21521768/warning-session-start-cannot-send-session-cookie-headers-already-sent-by

반응형