2013-07-08 4 views
0

안녕하세요이 PHP 코드 내 스크립트의 작은 부가 기능을 쓰기 위해 노력하고 있어요 사람입니다 : PHP는 페이지로 리디렉션

<?php 
if (isset($_SESSION['uid'])) { 
    header('Location: /members'); 
} else { 
    echo '<table width="40%" border="0" align="center" cellpadding="5" cellspacing="2"> 
    <tr align="center" valign="top"> 
    <td bgcolor="#99CC00" class="thinbord"><font color="#FFFFFF"><strong>قسمت ورود کاربران</strong></font></td> 
    </tr> 
    <tr align="center" valign="top" bgcolor="#EEF7FF"> 
    <td class="thinbord"><table width="100%" border="0" cellspacing="0" cellpadding="2"> 
     <form action="/members/" method="post"> 
      <tr> 
      <td height="25" align="center" valign="bottom" class="boxtext"><strong>email :</strong></td> 
      </tr> 
      <tr> 
      <td align="center" class="boxtext"><input type="text" name="email" size="20" maxlength="100"></td> 
      </tr> 
      <tr> 
      <td align="center" class="boxtext"><strong>پسورد:</strong></td> 
      </tr> 
      <tr> 
      <td align="center" class="boxtext"><input type="password" name="passwd" size="20" maxlength="20"></td> 
      </tr> 
      <tr> 
      <td align="center" class="boxtext"><input type="hidden" name="form" value="sent" > 
       <input name="submit" type="submit" value="login" ></td> 
      </tr> 
      <tr> 
      <td align="center" class="boxtext"><a href="/lost.php<? if ($ref) {echo("?ref=$ref"); }?>">lost your pass click here</a> 
       <br>please check your spam</b></td> 
      </tr> 
      <tr> 
      <td align="center" class="boxtext"><a href="/signup.php<? if ($ref) {echo("?ref=$ref"); }?>">sign up</a></td> 
      </tr> 
     </form> 
     </table></td> 
    </tr> 
</table>'; 
}?> 

가 가능한 경우에도 세션 UID 스크립트를 보여

이 회원에 페이지를 리디렉션과 그렇지 않은 경우 사용 가능한 스크립트 로그인 테이블 표시 세션이 시작되기 전에 인덱스가이 페이지로 이동하지만 작동하지 않으며 멤버에게 페이지가 리디렉션되지 않습니다. 나는이 문장을 생각

+2

당신은 스크립트에'session_start()'를 포함 시켰습니까? 세션을 처리 할 때 각 스크립트에'session_start()'를 추가해야합니다. –

+0

var_dump ($ _ SESSION) 여기에 덤프 된 답변을 게시하십시오. –

답변

0

header('Location: /members');

header('Location: http://www.example.com/'); 

php.net 그

헤더 문자열과 같은 말을 뭔가를 필요로한다. 특별한 경우 헤더 호출에는 두 가지가 있습니다. 첫 번째 문자는 "HTTP /"(대소 문자는 중요하지 않음) 문자열로 시작하는 헤더이며 보낼 HTTP 상태 코드를 파악하는 데 사용됩니다. 예를 들어 PHP 스크립트를 사용하여 ErrorDocument 지시어를 사용하여 파일 누락 요청을 처리하도록 Apache를 구성한 경우 스크립트에서 적절한 상태 코드를 생성하도록 할 수 있습니다.
두 번째 특별한 경우는 "위치 :"헤더입니다. 이 머리글을 브라우저로 다시 보낼뿐만 아니라 201 또는 3xx 상태 코드가 이미 설정되어 있지 않으면 브라우저에 REDIRECT (302) 상태 코드를 반환합니다.

코드에 http://이 필요하다고 생각합니다.

이렇게 하시겠습니까 header('Location: http://www.google.com/');. 그래서, Google로 리디렉션하면 코드가 정확합니다. 그렇지 않다면 뭔가를 바꿔야합니다.

+0

고맙지 만 코드가 작동하지 않습니다. – Farsad

+0

http://www.google.com에서 헤더를 사용하도록 설정하십시오. Google로 리디렉션하면 코드가 정확합니다. 그렇지 않다면 뭔가를 바꿔야합니다. –