What is the correct syntax for using header(Location: URL) in PHP to redirect to a specific URL?
When using the header() function in PHP to redirect to a specific URL, the correct syntax is to use the Location header followed by the URL you want to redirect to. It is important to note that there should not be any output sent to the browser before using the header() function, as headers must be sent before any content. Additionally, the URL should be an absolute URL including the protocol (http:// or https://).
<?php
// Redirect to a specific URL
header("Location: https://www.example.com");
exit;
?>
Keywords
Related Questions
- How can UTF-8 encoding be utilized to prevent character encoding issues in PHP emails?
- What are the potential challenges of changing the working directory before including a file in PHP?
- What potential pitfalls should PHP developers be aware of when hosting their websites on different servers with varying PHP versions?