2

I want to pass a url like http://example.com/test?a=1&b=2 in url segment of codeigniter.

I'm trying to pass something like this http://myurl.com/abc/http://example.com/test?a=1&b=2 and get the "http://example.com/test?a=1&b=2" url. What should be the best way to do this?

3 Answers 3

4

Set your URI protocol to REQUEST_URI in application/config/config.php , like this:

$config['uri_protocol'] = 'REQUEST_URI';

then use GET method:

$this->input->get('a');

EDIT:

Since http://example.com/test?a=1&b=2 is not encoded URL, it isn't possible. So first, I would encode URL with urlencode function like this:

urlencode('http://example.com/test?a=1&b=2');

it returns something like: http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2

So I would pass the URL like this:

http://myurl.com/?url=http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2

then get an example URL with GET method.

$this->input->get('url');
Sign up to request clarification or add additional context in comments.

1 Comment

How would you do this without a get variable? Can you add it as a URI segmenent like so: example.com/index.php/controller/method/var1/var2 ?
0

Use this technique to get the URL

$url = "http://example.com/test?a=1&b=2";
$segments = array($controller, $action, $url);
echo site_url($segments);

// or create a anchor link
echo anchor($segments, "click me");

Comments

0

Pass urlendode()'d URL in segment and then decode it with own (MY_*) class:

application/core/MY_URI.php:

<?php

class MY_URI extends CI_URI {

    function _filter_uri($str)
    {
        return rawurldecode(parent::_filter_uri($str));
    }
}

// EOF

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.