How to redirect to another URL from the view page in PHP CodeIgniter 4

To redirect from one URL to another, PHP provides a function called header(). By the pass URL in this function, we can easily redirect to another URL.How to redirect to another URL from the view page in PHP CodeIgniter 4

How to redirect to another URL from the view page in PHP CodeIgniter 4expoundsofttechsolution What is GMT? Step 1 First create a controller and create a function in it.

Step 2 Now code here whatever you want to do after that, return it to a view page. For example, here we return a view page named ‘Homepage’.



<?php namespace App\Controllers; 

use CodeIgniter\Controller;

Class AdvanceOptController extends Controller{

public function index()
{
//code here
return view('Homepage');
}

}
Step 3 Now create a view page and use our header() here. Like Below.

header("Location: www.example.com");
Make sure to pass exit() after apply header().