search

php remove https

May 28, 2023 pm 06:27 PM

随着互联网的快速发展,https已经逐渐成为了主流的网络连接方式。因为其能够为用户提供更为安全的数据传输和防止窃听的保障。然而,对于一些特定的开发场景,可能需要在php中将https去掉,本文将详细介绍如何实现这一需求。

一、什么是https

HTTPS全称为Hyper Text Transfer Protocol Secure,即是HTTP的安全形式。被广泛应用于安全性要求比较高的场景,如电子商务、网络银行、教务系统等。其通过SSL/TLS协议来保证网络数据传输的安全性,防止黑客和中间人攻击。

二、什么情况下需要去掉https

  1. 部分网站对性能要求比较高,https会降低web服务器的性能,去掉https能够提高网站的性能;
  2. 有些项目未考虑到安全性问题,待协议修改后未作相应的修改,不能直接使用https协议。
  3. 部分网站采用第三方平台提供的框架开发,这样不可控的第三方服务可能会影响他们的协议,导致开发者需要禁用https协议。

三、如何去掉https

  1. 修改网站配置文件

绝大部分的Web服务器应用都是从HTTP升级至HTTPS的。然而,恢复回HTTP也是同样可行的。在这个过程中,你无须修改代码,仅需改动web服务器应用配置文件即可。 以Nginx为例:

在http部分监听80端口,server部分重新定义相关配置

server{
    listen 80;
    server_name www.yourdomain.com;
    rewrite ^(.*) https://$server_name$1 permanent;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
}

server{
    listen 443 ssl;
    server_name www.yourdomain.com;
    ssl_certificate /etc/nginx/certs/yourdomain.crt;
    ssl_certificate_key /etc/nginx/certs/yourdomain.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers on;
    location / {
       proxy_pass http://127.0.0.1:8080;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

通过修改上述配置中的server段的监听端口号即可禁用https。

  1. 修改php.ini文件

也可以直接修改php.ini文件:

extension=php_openssl.dll

改为

;extension=php_openssl.dll

这样php代码中所有的https请求都将失效。

  1. 在php代码中禁用https

对于某些特定的php业务场景,需要在php代码中直接禁用https协议,代码如下:

$header = [
    'Content-Type: application/json',
];
$options = [
    'http' => [
        'header' =>$header,
        'method' => 'POST',
        'content' => json_encode($postData),
        'timeout' => 15 * 60, // 设置超时时间
        'ignore_errors' => true,
    ],
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
];
$context = stream_context_create($options);
// 发送请求
$res = file_get_contents($url, false, $context);

通过使ssl参数中的verify_peer和verify_peer_name为false来禁用https协议。

四、总结

https虽然已成为主流的网络连接方式,但在部分业务场景下,禁用https具有一定的必要性。上述三种禁用方式中,建议使用第一个方法,即通过修改web服务器应用配置文件来禁用https,通用性更加广泛。若禁用了https协议,一定要格外注意数据的安全哦!

The above is the detailed content of php remove https. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!