natanael-aguiar/safe-redirect

使用 PHP 简单安全地重定向页面的一种方法

v1.0.0 2023-10-13 11:30 UTC

This package is auto-updated.

Last update: 2024-09-13 14:28:35 UTC


README

安全重定向 是一个 PHP 包,它提供了一种简单安全的方法来在应用程序中执行 HTTP 重定向。它允许您使用可定制的 HTTP 状态码进行重定向,在处理用户导航时提供灵活性和安全性。

安装

您可以通过 Composer 安装 Safe Redirect。在终端中运行以下命令

composer require natanael-aguiar/safe-redirect

使用

要在应用程序中使用 Safe Redirect,首先导入 SafeRedirect 类,然后创建其实例。您可以在创建实例时传递自定义的 HTTP 状态码,或使用默认状态码,即 302(找到)。

<?php

require_once 'vendor/autoload.php';

use SafeRedirect\SafeRedirect;

// Creating a SafeRedirect instance with custom status code (optional)
$redirect = new SafeRedirect(301);

// Redirecting to a specific URL
$redirect->to('https://example.com');

在上面的示例中,使用 HTTP 状态码 301(永久移动)执行到 https://example.com 的重定向。

祝您玩得开心!