Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to redirect to another page

Short answer

Send the Location header and end the program:

<?php
 
header('Location: /login');
exit;

A permanent redirect

The default code is 302 — temporary. If the page moved for good, pass 301:

<?php
 
header('Location: /new-address', true, 301);
exit;

With parameters

Build the parameters with http_build_query() — it encodes the values by itself:

<?php
 
echo '/search?' . http_build_query(['q' => 'tea & coffee', 'page' => 2]);

Output:

/search?q=tea+%26+coffee&page=2

Functions used in this recipe

Thanks for reading!

Donate to the site — we work hard for you.