Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- class Redirect extends Core_Controller
- {
- function __construct()
- {
- parent::__construct();
- }
- //Get a URL key and redirect to the original URL
- function index()
- {
- $key = $this->uri->segment(1);
- if(empty($key)){ header('Location: /'.base_url()); exit;}
- //Get the data from the DB
- $this->load->model('url_model', 'url');
- if($data = $this->url->get_from_key($key))
- {
- //Update the click count
- $this->url->increase_clicks($data->id);
- //Redirect the user
- header('HTTP/1.1 301 Moved Permanently');
- header("Location: $data->original_url");
- }
- else
- {
- header('Location: '.base_url());
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement