What are the recommended HTTP status codes to use when implementing URL redirects in PHP?

When implementing URL redirects in PHP, it is recommended to use HTTP status codes to indicate the type of redirect being performed. The most commonly used status codes for redirects are 301 (Moved Permanently) and 302 (Found). A 301 redirect is used when a URL has permanently moved to a new location, while a 302 redirect is used for temporary redirects.

// Redirect to a new URL using a 301 status code (Moved Permanently)
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newurl.com");
exit;

// Redirect to a new URL using a 302 status code (Found)
header("HTTP/1.1 302 Found");
header("Location: http://www.newurl.com");
exit;