Header Function use in PHP and HTTP


There are various use of HEADER Function in PHP and HTTP like URL redirect , refresh, 301 redirection permanently etc so here PCDs provide questions and answers with example on all type of header function used in PHP

Top header function interview questions and answers

Questions : 1 Can we include header fuction in between HTML output of php page

No, We can't use header function in between any out put because it generate error if any out put like any content, white space, line , any tag like > html > etc send before header function so we must use header function befor any Out Put Send.

Questions : 2 How we can redirect a page to other page or site using php header

We can use header function like below to redirect
header('Location: http://www.pcds.co.in/');
at place of pcds.co.in we can write any site name or any internal page like
header('Location: blog.php');
and must there should not any space between Location and :
and http status code of this redirection is 302

Questions : 3 How we can do permanent redirect 301 a page to other page or site using php header

Answer : 3 by below code we can do permanent redirect 301
header("Location: /blog.php",TRUE,301);
OR header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.pcds.co.in/');

Questions : 4 How we can sent HTTP status using header funcion

Answer : 4 we can send HTTP status by below type of code
header("HTTP/1.0 404 Not Found");

Next Page

Ask your interview questions on


Write Your comment or Questions if you want the answers on from Experts

Name* :
Email Id* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---