Breaking News
Home / Web / PHP / PHP Snippets / How to write a utility method to print redirect in PHP?

How to write a utility method to print redirect in PHP?

  1. function redirect($uri = , $method = ‘location’,  $http_response_code = 302){
  2.  
  3.   if(!preg_match(‘#^https?://#i’, $uri)){
  4.         $uri = BASE_URL . $uri;
  5.     }
  6. switch($method){
  7.  case ‘refresh’ : header("Refresh:0;url=".$uri);
  8.         break;
  9.  default: header("Location: ".$uri, TRUE, $http_response_code);
  10.       break;
  11.  }
  12.  exit;
  13. }
[pb_builder]

Check Also

How to list files in a directory in PHP?

<?php if ($handle = opendir(‘/path/to/directory’)) {     echo "Directory handle: $handlen";     echo …

Advertisment ad adsense adlogger