Welcome Guest, Not a member yet? Register   Sign In
Redirection controller
#1

[eluser]frist44[/eluser]
I'm looking to make a redirection controller, so that each link going to an external will be recorded in the logs.

My thought is to make it of the form: www.domain.com/redir/url/http://website.com

However, if I try to query the last uri segment, I get "http:" because the next slash looks like another segment.

Any ideas to get this all as one string?

I suppose I could str replace the "/" in the URL with something else, but didn't know if there were better ideas.
#2

[eluser]Andrew Cairns[/eluser]
hi frist,
you could just remove the http:// and just do domain.com/redir/url/www.google.com/
if needed, you could add the http:// when it redirects from the controller.
#3

[eluser]frist44[/eluser]
But what if the actual URL itself had a slash in it. Ex. www.google.com/finance
#4

[eluser]Andrew Cairns[/eluser]
you could try urlencode() : http://php.net/manual/en/function.urlencode.php
#5

[eluser]frist44[/eluser]
I tried urlencode, but when I encode it, the system still interprets it as a "/" and says it can't find that function.

In my code I have:

Code:
redirection('www.google.com/finance');

Helper:

Code:
function redirection($strURL) {      
       $strURL = urlencode($strURL);      
        redirect(base_url() . 'redir/url/' . $strURL);
    }

Controller:

Code:
function url() {
    
       echo $this->uri->segment(3) . '<br />';
}
#6

[eluser]Andrew Cairns[/eluser]
you could append the rest of the uri segments if $this->uri->total_segments() > 3
#7

[eluser]frist44[/eluser]
good idea. I did that and then had to put everything back together.

Code:
if ($this->uri->total_segments() > 3 ){
            $arr_args = $this->uri->segment_array();
            $arr_args = array_slice($arr_args, 2);
            $strURL = implode('/', $arr_args);
            $strURL = str_replace(':/', '://', $strURL);
            
            redirect($strURL);
            exit;
        }




Theme © iAndrew 2016 - Forum software by © MyBB