• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Php Tip: Use header() to send a raw HTTP header

December 19, 2023

Php Tip: Use header() to send a raw HTTP header

When it comes to web development, PHP is one of the most popular programming languages. It offers a wide range of features and functions that make it easy to build dynamic and interactive websites. One such function is header(), which allows you to send a raw HTTP header to the browser.

What is a raw HTTP header?

Before we dive into the details of using the header() function, let’s first understand what a raw HTTP header is. When a web server sends a response to a browser, it includes a set of headers that provide additional information about the response. These headers can include details such as the content type, cache control, cookies, and more.

A raw HTTP header is a string of text that follows a specific format and contains information about the response. It typically consists of a header name followed by a colon and a space, and then the header value. For example, the Content-Type header specifies the type of content being sent, such as HTML, JSON, or XML.

Using the header() function

The header() function in PHP allows you to send a raw HTTP header to the browser. It takes a single argument, which is the header string you want to send. Let’s take a look at an example:

header("Content-Type: application/json");

In this example, we are using the header() function to set the Content-Type header to application/json. This tells the browser that the response will be in JSON format.

You can also use the header() function to set other headers, such as the Location header to redirect the browser to a different page:

header("Location: https://example.com");

This will redirect the browser to the specified URL.

Why use the header() function?

The header() function is particularly useful when you need to send specific headers to the browser. For example, if you are building a RESTful API, you can use the header() function to set the appropriate Content-Type header based on the requested resource.

Additionally, the header() function allows you to control the caching behavior of your web pages. By setting the Cache-Control header, you can specify how long the browser should cache the page and when it should request a fresh copy from the server.

Conclusion

The header() function in PHP is a powerful tool that allows you to send raw HTTP headers to the browser. It provides you with fine-grained control over the response headers, allowing you to set the appropriate content type, redirect the browser, and control caching behavior.

For more information about PHP and web development, consider exploring Server.HK, a leading VPS hosting company that offers top-notch hosting solutions for your website.

Recent Posts

  • How to Host a Python Flask or Django Application on Hong Kong VPS (2026)
  • How to Set Up WireGuard VPN on a Hong Kong VPS: Step-by-Step Guide 2026
  • Hong Kong VPS vs DigitalOcean: Cost, Performance, and China Routing Compared (2026)
  • VPS Hosting vs Shared Hosting: Why the Upgrade Is Worth It for Asia-Facing Websites
  • Hong Kong VPS vs Google Cloud Asia: Which Delivers Better China Performance in 2026?

Recent Comments

  1. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  2. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  3. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  4. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  5. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot