0

I'm having issues with routing in code igniter. I've got the basics working though.

$route['user/authorize'] = "user/asdf";

That dummy line is working fine. This isn't:

$route['user/authorize?code=:any'] = "user/asdf";

and especially

$route['user/authorize?code=:any'] = "user/authorize/$1";

I already changed the $config['permitted_uri_chars'] variable to an empty string (allow all).

I've also tried using (:any) with brackets. I've assumed it was a typo in the manual, since (:num) uses brackets as well. To no effect.

I'm out of ideas. Anyone?

BTW the code variable is a Facebook access token and look something like this:

2.TOCElrzcR5MYz_J8O67hWA__.3600.1295467200-17044424246|4FPbz0N-pXqGWYR81PWGPTY06A4

Not sure if it's relevant, my .htacces file:

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images)
RewriteRule ^(.*)$ /website/index.php/$1 [L]

3 Answers 3

1

Since the Codeigniter Structure is:

Controller / Method / Params

I assume that :

User/authorize

is your controller/method.

Now,

$route['user/authorize?code=:any'] = "user/asdf";

Should be :

$route['user/authorize/:any'] = "user/asdf";

where

function authorize($code = null) { echo $code; }

will output same as

function authorize(){ $code = $_GET['code']; }

So oldskool php you write : ninja.php?code=something

in CI is third segment.


/user/authorize/TOCElrzcR5MYz_J8O67hWA__.3600.1295467200-17044424246|4FPbz0N-pXqGWYR81PWGPTY06A4

is equal to

ninja.php?code=TOCElrzcR5MYz_J8O67hWA__.3600.1295467200-17044424246|4FPbz0N-pXqGWYR81PWGPTY06A4

as explained on the begining.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. I undestand what you mean. But there is still a problem. I noticed the redirect works like you tell. But :any won't work if there is a question mark in it (which there is). I tested with a regular random string and that works fine. Problem is I don't get to choose the question mark. Facebook adds it to my URL. I specify the URL, facebook adds the ?code=blah parameter. So I'm getting closer...
Can you try to see if: $config['enable_query_strings'] = TRUE; $config['uri_protocol'] = "PATH_INFO"; This is how I use both when I have to. and echo $_GET['code'];
0

I believe you need to add the following lines to your config:

$config['enable_query_strings'] = TRUE;
$config['uri_protocol'] = "QUERY_STRING";

Source

2 Comments

But I'm using the 'nice URL structure'. If I'm enabling query strings I'll lose that (it's an exclusive choice, can't have both). Might be my last resort though. Hope anyone else has an idea. Am also investigating adding a line to my .htacces....
Sorry, you're right, it is exclusive. Alternatively, you could probably $route['user/authorize'] = 'user/authorize' and do your own routing inside the the authorize method.
0
$config['uri_protocol'] = "PATH_INFO";

Leave everything else to the default.

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.