How to send http 301 or 302 to redirect other page in PHP

How to send http response header using php?

We can send 301 or 302 response header to clients to redirect other page by php. You can view some detailed inforamtion on this:
How to send http response header by php

How to send 301 or 302 response header?

Here is a php example for redirecting other page by 301 or 302, you can use it easily.

function gotopage($url,$static_code=301){
if($static_code==301){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$url);
exit();
}
if($static_code==302){
header("HTTP/1.1 302 Found");
header("Location: ".$url);
exit();
}
}

You can use like this:

<?php
gotopage($url='https://www.exampleinsight.com/',$static_code=301);

?>