Leorisar
0
Q:

header php


<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>

0

<?php

header("Content-type:application/pdf");



// It will be called downloaded.pdf

header("Content-Disposition:attachment;filename='downloaded.pdf'");



// The PDF source is in original.pdf

readfile("original.pdf");

?>



<html>

<body>



...

...
 
1

<?php

// $file and $line are passed in for later use

// Do not assign them values beforehand

if (!headers_sent($file, $line))

  {

  header("Location: https://www.w3schools.com/");

  exit;

  // Trigger an error here

  }

else

  {

  echo "Headers sent in $file on line $line";

  exit;

  }

?>



<html>

<body>



...

...
 
1

header(header, replace, http_response_code)
1
header ( string $header [, bool $replace = TRUE [, int $http_response_code ]] ) : void
2

<?php

  if (!headers_sent()) {

  header("Location: https://www.w3schools.com/");

  exit;

  }

?>



<html>

<body>



...

...
 
0

<?php

// Date in the past

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

header("Cache-Control: no-cache");

header("Pragma: no-cache");

?>



<html>

<body>

...

...
 
0

headers_sent(file,line)
0

<?php

setcookie("TestCookie","SomeValue");

header("X-Sample-Test: foo");

header("Content-type: text/plain");

?>



<html>

<body>



<?php

var_dump(headers_list());

?>



</body>

</html>
 
0

New to Communities?

Join the community