Swoole\Http\Response->redirect()

Latest version: pecl install openswoole-4.11.1

Declaration

<?php Swoole\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(Swoole/Server/Request $request, Swoole/Server/Response $response)
{
    $response->redirect("https://openswoole.com/", 301);
});
Last updated on March 31, 2022