PHP Header() Function

PHP Header Function

The header() function has various uses. It can output headers for an xml file, force downloads and redirect pages to a new url. If it is used to redirect a url, there must not be any html or text of any sort.

Redirect With Header() Function

To redirect with header(),
1) Type: header("Location: filename.php");

PHP Force Downloading

   header("Content-Type: application/force-download");
   //the filename will be given below
   header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($myfilename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');


header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8" ?>'.'<?xml-stylesheet type="text/xsl" href="sitemap.xsl"?>';

echo '<urlset xmlns:xsi="" xsi:schemaLocation="" xmlns="">';