T086ѧϰ�� | վ��ѧԺ | �����ĵ� | ���� | Ъ���� | IP��ַ��ѯ | �������� | ���ջ��� | �����ֵ� | ���ù��� | ������Ϣ��ѯ

header()����ʹ��˵��

�� �������ߣ����� ����ʱ�䣺2008-10-20 | ���壺�� �� С��
[����]header()����ʹ��˵���� һ�����ã� ~~~~~~~~~ PHPֻ����HTTPЭ�齫HTML�ĵ��ı�ͷ�͵�������������������������ô��������ҳ�棬���ڴ��͵���������Ҫ��Ϥһ��HTTPЭ���ˣ���PHP�޹��ˣ��ɲ���http://www.w3.org/Pr...
header()����ʹ��˵����  
 
һ�����ã�  
~~~~~~~~~  
       PHPֻ����HTTPЭ�齫HTML�ĵ��ı�ͷ�͵�������������������������ô��������ҳ�棬���ڴ��͵���������Ҫ��Ϥһ��HTTPЭ���ˣ���PHP�޹��ˣ��ɲ���http://www.w3.org/Protocols/rfc2616/rfc2616��  
       ��ͳ�ı�ͷһ�������������ֱ�ͷ֮һ����ֻ�ܳ���һ�Ρ�  
       Location:  xxxx:yyyy/zzzz  
       Content-Type:  xxxx/yyyy  
       Status:  nnn  xxxxxx  
 
���������˽�һ��HTTPЭ����������ʽ  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
       HTTPЭ���ǻ�����������Ӧ��ʽ�ġ�һ���ͻ������������������Ӻ󣬷���һ����������������������ʽ�ĸ�ʽΪ��ͳһ��Դ��ʶ����Э���汾�ţ�������MIME��Ϣ�����������η����ͻ�����Ϣ�Ϳ��ܵ����ݡ��������ӵ������󣬸�����Ӧ����Ӧ��Ϣ������ʽΪһ��״̬�а�����Ϣ��Э���汾�š�һ���ɹ��������Ĵ��룬������MIME��Ϣ������������Ϣ��ʵ����Ϣ�Ϳ��ܵ����ݡ�  
       �����ĸ����̣���HTTPЭ���У���������ָ�ṩHTTP�����IJ��֣��ͻ�����ָ��ʹ�õ��������������ع��ߵȵȡ���ͨѶʱ���ɿͻ��˷����������ӣ������˽������ӣ�Ȼ�󣬿ͻ��˷���HTTP������Request���������˷�����Ӧ��Ϣ��Respond�����ɴ�����һ��HTTP������  
 
����HTTPЭ��״̬����ʾ����˼  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
����1������������  
����2����������ʾ�����ɹ��ؽ���  
����3��������Ϊ���������ͻ�����һ��ϸ������  
����4���������ͻ�����  
����5������������������  
 
�ġ�����ʵ����  
~~~~~~~~~~~~~  
   <1>  �ض������ܣ��������  
       <?php  
           Header("Location:  http://www.php.net");    
       ?>  
 
   <2>  ǿ���û�ÿ�η�������ҳ��ʱ��ȡ�������ϣ�������ʹ�ô��ڿͻ��˵Ļ��档  
       <?php  
           //������������ҳ���Ĺ���ʱ��(�ø�������ʱ����ʾ)��ֻҪ���Ѿ���ȥ�����ڼ��ɡ�  
           header("Expires:  Mon,  26  Jul  1970  05:00:00  GMT");  
           //������������ҳ����������������(�ø�������ʱ����ʾ)Ҳ���ǵ���,Ŀ�ľ���ǿ����������ȡ��������  
           header("Last-Modified:  "  .  gmdate("D,  d  M  Y  H:i:s")  .  "GMT");  
           //���߿ͻ�����������ʹ�û���  
           header("Cache-Control:  no-cache,  must-revalidate");  
           //����������ǰ�ķ��������ݣ�,������HTTP1.0Э��  
           header("Pragma:  no-cache");      
           //����MIME����  
           header("Content-type:  application/file");      
           //�ļ�����  
           header("Content-Length:  227685");      
           //���ܵķ�Χ��λ  
           header("Accept-Ranges:  bytes");  
           //ȱʡʱ�ļ������Ի����е��ļ�����  
           header("Content��Disposition:  attachment;  filename=$filename");  
       ?>  
 
   <3>  ����״ֵ̬������������Ҫ���ڷ���Ȩ�޿���  
       <?php  
           header('HTTP/1.1  401  Unauthorized');  
           header('status:  401  Unauthorized');  
       ?>  
           ����Ҫ����һ���û����ܷ��ʸ�ҳ����������״̬Ϊ404��������ʾ����������������ʾΪ����ҳ������  
       <?php  
           header('HTTP/1.1  404  Not  Found');  
           header("status:  404  Not  Found");  
       ?>  
  • ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
  • �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
������ѯ Health Check Gulangyu
© 2017 T086ѧϰ�� - T086.com(ԭitlearner.com)
RunTime:11.38ms QueryTime:7