OpenSwoole\Http\Response->redirect()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Http\Response->redirect(string $url, int $httpStatusCode = 302): void

Parameters

url

The new address/location to jump to

httpStatusCode

The redirection HTTP status code, 302 means it was temporary and 301 represents a permanent jump

Return

None

Description

Redirect a HTTP client to a new address/location. Set the redirect status code which indicates the type of jump, default is 302.

Calling this redirect method will automatically call $response->end('') for you and will end the response.

Example

<?php

$server->on('Request', function(OpenSwoole\Server\Request $request, OpenSwoole\Server\Response $response)
{
    $response->redirect("https://openswoole.com/", 301);
});
Last updated on September 20, 2022