Welcome Guest, Not a member yet? Register   Sign In
An Error Was Encountered: The URI you submitted has disallowed characters.
#1

[eluser]BoyBlue[/eluser]
Hello—

I’m new to CI so please be kind…

I’m trying to create a link in an Email that when clicked will come to a Page on my site that will be able to retrieve the member’s email by using “$this->uri->segment(3);

I am successfully sending/receiving the email with the link…However, when the link is clicked I get the following error:

An Error Was Encountered
The URI you submitted has disallowed characters.

In the browser, segment(3) looks like this:

/ % 0 9 % 0 9 % 0 9 % 0 9 % 0 9 memberemail @ mail . com
(I put those spaces in the % 0 9 for the initial post because if they were not in there it posts it as an email link without the % 0 9 element…)

I’m guessing my problem is the ” % 0 9 ” stuff—

Here is the relevant code creating the link in the email:
$member_email = $this->input->post(‘email’); (obviously grabbing the email from the form)
$message = ” hypertext stuff and then localhost/beta/index.php/login/login_email/”.$member_email .”;
(Email send code including…)
$this->email->message($message);


First of all, is the ” % 0 9 ” stuff normal? And, if so, what is the best practice for me to successfully load the page and retrieve the email?

(I tried to include the email message code—but, wasn’t allowed due to it looking like a link…)

thanks,
BoyBlue
#2

[eluser]Sergio B[/eluser]
Sorry but I couldn't determine where those % 09 are coming from, in the code you posted it seems like the generated link would be something like:

Code:
localhost/login/login_email/[email protected]


So the only thing I can think about is that those % 09 are in the $member_email variable, maybe you should try to trim it before creating the link anchor. Still it would help a lot to see your code.
#3

[eluser]BoyBlue[/eluser]
Thanks for the input Sergio B...I am definitely trimming the email, so I know the % 0 9 isn't being created from the "form input"...

Anyone else have suggestions...?

thanks,
BoyBlue
#4

[eluser]BoyBlue[/eluser]
Ok...so, I figured out a solution.

There are actually 2 problems.

Problem #1:
% 0 9

Solution:
This was fixed when I changed to generating my URI Link in the email message to: site _ url(" login / verify_pwrc / $member_email / ")


Problem #2:
Error: The URI you submitted has disallowed characters
(I think this is being caused by settings in MAMP and/or Snow Leopard)

Solution:
I found some help at david michael thompson' s site:
Quote:Snow leopard upgraded my php dev environment to 5.3 from 5.2.6 And a few things have changed since then. Namely php bug #47229 “preg_quote should escape “-” (minus) as well” was fixed. (technically in 5.2.8) CodeIgniter checks uri for allowed characters to prevent some bad things. But the use preg_quote to convert the allowed list of character to something usable in a regular expression. Now the minus “-”, or I’d call it a dash (but I know there is a longer character for that) gets escaped in preg_quote with a backslash “\”. That cause the expression “a-z 0-9″ to be converted to “a\-z 0\-9″ which will not work in a regex.
Quote:How to fix it. (assuming codeigniter 1.7)

1) in codeigiter system/libraries open URI.php line 189 you’ll find

if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", rawurlencode($str)))
Change that to:

if ( ! preg_match("|^[".($this->config->item('permitted_uri_chars'))."]+$|i", rawurlencode($str)))
Note we removed the preg_quote(). Now in your system/application/config/config.php file look for line 126 (unless you’ve added a lot to you config will be around there somewhere)

Change the line

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
to:

$config['permitted_uri_chars'] = 'a-z 0-9~%\.\:_\-';
we’re now preparing our allowed character string in the config file and skipping preg_quote. And that’s it. Now your uri should work

I hope this helps out someone else out there so they don't have as frustrating a day as I had trying to figure this out.

If there is a better solution(best practice) to this I would love to know what it is...

good luck,
BoyBlue
#5

[eluser]IAmThePat[/eluser]
Is there any update on this fix for CI 2.0? I tried removing the preg_quote as described, but the line in URI is different (Below)

Code:
if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))

Then if I remove preg_quote I get the following error:

Code:
Fatal error: Only variables can be passed by reference in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\n2m\system\core\URI.php on line 214

any assistance would be appreciated.

Thanks
#6

[eluser]BoyBlue[/eluser]
Hi IamthePat-

Did you have a chance to try the 2 suggestions I made in the message just above yours...?

You could be having the problem due to 2 possible reasons....Either the URI needs to be adjusted like I did mine. OR, you may have had an updage to your PHP. In the case of both please see my notes above.

let me know if there's anything else I can do to help.
BoyBlue
#7

[eluser]IAmThePat[/eluser]
[quote author="BoyBlue" date="1299981065"]Hi IamthePat-

Did you have a chance to try the 2 suggestions I made in the message just above yours...?

You could be having the problem due to 2 possible reasons....Either the URI needs to be adjusted like I did mine. OR, you may have had an updage to your PHP. In the case of both please see my notes above.

let me know if there's anything else I can do to help.
BoyBlue[/quote]

Hi,

Thanks for getting back. I did check your suggestions. The issue is definitely because I upgraded my PHP. I have a previous version running on another box, and the query string works without issue.

My query string is /?r=[md5 hash]&e=[email address]

Not too much I can change in there.

As for the second solution, my original issue was posted above. The if() is different in the URI.php file then the one in your example. I still removed the preg_quote() and adjusted the allowed character set. PHP spits out a fatal error:

Fatal error: Only variables can be passed by reference in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\n2m\system\core\URI.php on line 214 (The line where preg_quote() was located)

so I am thinking that it isn't linking $this->config->item('permitted_uri_chars') in the preg_match.
#8

[eluser]BoyBlue[/eluser]
Sounds like you may be on the right track. Did you take a look at Michael's website?
#9

[eluser]IAmThePat[/eluser]
Well, after looking a bit more, I found on the bitbucket repository for CI, a bug report similar to this issue, which fixed my problem.

I am using the default controller to catch the query string. Apparently to do this though you must have the default controller in the URL in order for it to work.

Example:
http://mysite.com/welcome/?test=nice -- Works
http://mysite.com/?test=nice -- Fails

Thanks for your assistance, and getting back to me
-Pat
#10

[eluser]BoyBlue[/eluser]
Good work Pat! Sorry you had to go through this...I know it can be frustrating.




Theme © iAndrew 2016 - Forum software by © MyBB