WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : header -- Send a raw HTTP header
Categories : PHP, PHP Functions, HTTP Update Picture
documentation group PHP
Date : Apr 30th 1999
Grade : 2 of 5 (graded 3 times)
Viewed : 5635
File : No file for this code example.
Images : No Images for this code example.
Search : More code by documentation group PHP
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Description

</H2
><DIV
CLASS="funcsynopsis"
><A
NAME="AEN15314"
></A
><P
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int <B
CLASS="function"
>header</B
></CODE
> (string string)</CODE
></P
><P
></P
></DIV
><P
>&#13; The <B
CLASS="function"
>Header()</B
> function is used at the top of an
<SPAN
CLASS="acronym"
>HTML</SPAN
> file to send raw <SPAN
CLASS="acronym"
>HTTP</SPAN
>
header strings. See the <A
HREF="get_example.php3?Function=http://www.w3.org/Protocols/rfc2616/rfc2616"
TARGET="_top"
>HTTP 1.1
Specification</A
> for more information on raw http headers.
</P
><P
>&#13; There are two special-case header calls. The first is the
"Location" header. Not only does it send this header
back to the browser, it also returns a REDIRECT status code to
Apache. From a script writer's point of view this should not be
important, but for people who understand Apache internals it is
important to understand.
<DIV
CLASS="informalexample"
><A
NAME="AEN15326"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>&#13;header ("Location: http://www.net"); /* Redirect browser
to PHP web site */
exit; /* Make sure that code below does
not get executed when we redirect. */
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
</P
><P
>&#13; The second special-case is any header that starts with the
string, "HTTP/" (case is not significant). For
example, if you have your ErrorDocument 404 Apache directive
pointed to a PHP script, it would be a good idea to make sure
that your PHP script is actually generating a 404. The first
thing you do in your script should then be:
<DIV
CLASS="informalexample"
><A
NAME="AEN15329"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>&#13;header ("HTTP/1.0 404 Not Found");
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
</P
><P
>&#13; PHP scripts often generate dynamic HTML that must not be cached
by the client browser or any proxy caches between the server and the
client browser. Many proxies and clients can be forced to disable
caching with
<DIV
CLASS="informalexample"
><A
NAME="AEN15332"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>&#13;header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
</P
><P
>&#13; Remember that the <B
CLASS="function"
>header()</B
> function must be
called before any actual output is sent, either by normal HTML
tags blank lines in a file, or from PHP. It is a very common
error to read code with <A
HREF="get_example.php3?Function=include"
><B
CLASS="function"
>include()</B
></A
>, or
<A
HREF="get_example.php3?Function=require"
><B
CLASS="function"
>require()</B
></A
>, functions, or another file access
function, and have spaces or empty lines that will output before
<B
CLASS="function"
>header()</B
> is called. The same problem exists
when using a single PHP/HTML file.
<DIV
CLASS="informalexample"
><A
NAME="AEN15339"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>&#13;&#60; require("user_logging.inc") ?&#62;


&#60; header ("Content-Type: audio/x-pn-realaudio"); ?&#62;
// Broken, Note the blank lines above
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
</P
><P
>&#13;

See also <A
HREF="get_example.php3?Function=headers-sent"
><B
CLASS="function"
>headers_sent()</B
></A
>



Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals.
Categories : PHP, Filesystem, Cache, Sockets, HTTP
Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP
Categories : PHP, HTTP, Regexps
A function to check if a URL exists
Categories : PHP, CURL, HTTP
PHP4 HTTP Compression Speeds up the Web
Categories : PHP, Zlib, HTML and PHP, HTTP, Network
WebServerSpy checks which kind of Webserver is running, Apache, Netscape, Fasttrack, IIS, HTTP-Header, HTTP 1.0, GET, spy, WWW
Categories : HTTP, Network, Apache, PHP, Web Servers
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
Authentication HTTP protocol POST
Categories : Authentication, HTTP, PHP
This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { }
Categories : HTTP, Arrays, PHP
Remote File Size
Categories : PHP, Filesystem, HTTP, Sockets
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
How to force the user to download a file instead of opening it up in an controlled environment within the browser (i.e. MS Word/Adobe Acrobat)
Categories : Browsers, PHP, HTTP
This script shows you the 7th latest php items from the mailing list archive on zend.com
Categories : HTML, HTML and PHP, HTTP, PHP
The first step Guest Book ... ^^
Categories : MySQL, PHP, Apache, HTML, HTTP
Gonx Proxy - This class is meant to act as an HTTP proxy to serve pages of a remote server as if they were local pages.
Categories : PHP, PHP Classes, HTTP
HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP