<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Link extends CI_Controller {

	public function __construct() {
	  parent::__construct();
	  $this->load->model('keyword_model');
	  $this->load->helper('cookie');
	  $this->load->database(); 
	  
	}

	public function index(){
	    
		 $keyword_hash=$this->keyword_model->get_campaign_one_hash($_GET['uid']);
		 
	    $url=$keyword_hash->url;
	    $url_keywords=$keyword_hash->keywords;
	    (preg_match_all('/"([^"]+)"/',$url_keywords,$m));
	    foreach($m[0] as $key => $value) 
	    {
	        if($key&1) 
	          {
	              unset($m[0][$key]);
	          }
	    }  
	    
	    $randIndex = array_rand($m[0]);
	    $final_url=str_replace("{{keyword}}",str_replace('"', '', $m[0][$randIndex]),$url);
	    $final_url_without_https=str_replace("https",'http',$final_url);
	   // die($final_url_without_https);
	    header("Location: $final_url_without_https");
        die();
	}

}