search
HomeBackend DevelopmentPHP ProblemHow does PHP obtain the header information of a specified URL and hide and close it?

1. How to obtain the header information of the specified URL in PHP

Super simple, just one line of command:

<?php print_r(get_headers(&#39;https://www.mdaima.com&#39;));?>
 
Array
(
    [0] => HTTP/1.1 403 Forbidden
    [1] => Date: Sun, 24 Jan 2021 05:09:48 GMT
    [2] => Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1i PHP/7.3.26
    [3] => Content-Length: 199
    [4] => Connection: close
    [5] => Content-Type: text/html; charset=iso-8859-1
)

2. How to disable display or The method of hiding header information

is divided into two steps. The first step is to change expose_php = On in the PHP.ini file to expose_php = Off, after restarting Apache, take another look at

Array
(
    [0] => HTTP/1.1 403 Forbidden
    [1] => Date: Sun, 24 Jan 2021 05:10:50 GMT
    [2] => Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1i
    [3] => Content-Length: 199
    [4] => Connection: close
    [5] => Content-Type: text/html; charset=iso-8859-1
)

After restarting, we can see that the information about the PHP version is no longer displayed , but the information of Apache and service name is still displayed. We need to be more thorough to ensure safety. We need to add two instructions to Apache's httpd.conf. First, let's confirm whether there are the following two configuration instructions in Apache's httpd.conf file. If not, directly add two lines of data at the bottom of the configuration file.

ServerTokens Prod
ServerSignature Off

For the instruction configuration parameters of ServerTokens, please see the instructions below:

ServerTokens Prod   显示“Server: Apache”
ServerTokens Major  显示 “Server: Apache/2″
ServerTokens Minor  显示“Server: Apache/2.2″
ServerTokens Min   显示“Server: Apache/2.2.17″
ServerTokens OS   显示 “Server: Apache/2.2.17 (Unix)”
ServerTokens Full   显示 “Server: Apache/2.2.17 (Unix) PHP/5.3.5″ (如果未指定任何的值,这个是默认的返回信息)

Instructions for ServerSignature On:

           When set to On, when a user requests to access the webpage of our website that does not exist, the server will display an error message. The error message will include the name of the server and Apache at the bottom of the page. Version and other related information are displayed, which will provide some convenience for some unscrupulous people to exploit known version vulnerabilities. So we'd better not display this information, we can set this parameter to Off.

By modifying these two parameter configuration files, the final effect of obtaining header is as follows:

Array
(
    [0] => HTTP/1.1 403 Forbidden
    [1] => Date: Sun, 24 Jan 2021 04:54:49 GMT
    [2] => Server: Apache
    [3] => Content-Length: 258
    [4] => Connection: close
    [5] => Content-Type: text/html; charset=iso-8859-1
)

Recommended: "php video tutorial"《php tutorial

The above is the detailed content of How does PHP obtain the header information of a specified URL and hide and close it?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:码代码-李雷博客. If there is any infringement, please contact admin@php.cn delete
SpringBoot怎么通过Feign调用传递Header中参数SpringBoot怎么通过Feign调用传递Header中参数May 16, 2023 pm 08:38 PM

【SpringBoot】通过Feign调用传递Header中参数如何通过Feign传递Header参数问题描述我们在SpringCloud中使用Feign请求另一个服务的Api接口时,有将Header中参数传递下去的需求,如果不做特殊处理,就会将Header中的参数丢失。解决方案方案一:通过@RequestHeader(name="headerName")来传递例如:Feign定义如下@FeignClient(name="service-name")pub

linux的header是什么意思linux的header是什么意思Jul 18, 2023 pm 03:34 PM

linux的header是指在文件或数据流中的开头部分,用于包含关于内容的元数据,通过正确地编写和使用Header文件,开发者能够更好地利用系统资源,提高代码的可读性和可维护性。

如何使用PHP header()方法来调整网页如何使用PHP header()方法来调整网页Mar 28, 2023 pm 01:54 PM

PHP是一种功能强大的编程语言,可以用来创建动态网站和Web应用程序。其中一个最强大的功能之一是PHP的header()方法。在本文中,我们将探讨如何使用PHP的header()方法来调整网页。

php header头怎么实现跳转php header头怎么实现跳转Dec 02, 2022 am 09:14 AM

php header实现跳转的方法:1、使用“Header("Location:$url");”语法实现跳转;2、使用if判断式实现跳转,其跳转语句如“if($_COOKIE["u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');”。

html5标签head和header有什么区别html5标签head和header有什么区别Jan 17, 2022 am 11:10 AM

区别:1、head标签用于定义文档头部,它是所有头部元素的容器,而header标签用于定义文档的页眉(介绍信息);2、浏览器都支持head标签,而旧版本浏览器均不支持header标签,需要IE9+以上浏览器才支持header标签。

Nginx如何通过header中的标识进行分发Nginx如何通过header中的标识进行分发May 11, 2023 pm 04:01 PM

Nginx可以根据请求头中自定义的标识将请求分发到不同的服务器。具体来说,可以使用map指令将请求头中的自定义标识映射为不同的后端服务器地址,然后使用proxy_pass指令将请求转发到对应的后端服务器。以下是一个示例配置文件:http{map$http_my_header$backend{defaultbackend1.example.com;value1backend2.example.com;value2backend3.example.com;}upstreambackend1{serv

PHP文件下载函数大全:readfile、header、Content-Disposition等函数的文件下载实例分析PHP文件下载函数大全:readfile、header、Content-Disposition等函数的文件下载实例分析Nov 18, 2023 pm 03:26 PM

PHP文件下载函数大全:readfile、header、Content-Disposition等函数的文件下载实例分析文件下载是Web应用程序中必不可少的功能之一,而PHP作为一种广泛使用的Web开发语言,提供了多种实现文件下载的函数和方法。本文将介绍PHP中常用的文件下载函数,包括readfile、header、Content-Dispo

怎么通过Nginx定义Header头信息怎么通过Nginx定义Header头信息May 16, 2023 am 11:52 AM

通过修改nginx的conf文件,轻松达到自定义HTTPHeader的目的。Nginx使用ngx_headers_more模块来增加、删除出站、入站的Header信息。默认该模块没有加入到Nginx的源码中,要想使用相关功能需要在编译Nginx时加入该模块。本人服务器中的Nginx在编译时没有加入该模块,使用-V查看当前Nginx的编译参数:[root@z-dig~]#nginx-Vnginxversion:www.z-dig.combuiltbygcc4.4.720120313(RedHat4

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),