Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Redirect extends Core_Controller
  4. {
  5.  
  6.         function __construct()
  7.         {
  8.                 parent::__construct();
  9.         }
  10.         //Get a URL key and redirect to the original URL
  11.         function index()
  12.         {
  13.                 $key = $this->uri->segment(1);
  14.  
  15.                 if(empty($key)){ header('Location: /'.base_url()); exit;}
  16.  
  17.                 //Get the data from the DB
  18.                 $this->load->model('url_model', 'url');
  19.                 if($data = $this->url->get_from_key($key))
  20.                 {
  21.                         //Update the click count
  22.                         $this->url->increase_clicks($data->id);
  23.  
  24.                         //Redirect the user
  25.                         header('HTTP/1.1 301 Moved Permanently');
  26.                         header("Location: $data->original_url");
  27.                 }
  28.                 else
  29.                 {
  30.                         header('Location: '.base_url());
  31.                 }
  32.         }
  33.  
  34. }
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement