• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server.UrlEncode from Asp.net to codeigniter

#1
[eluser]bleu[/eluser]
i am using this in my asp.net website when outputting a value from the database into a link
Code:
<a href="+ Server.UrlEncode(value_to_be_encoded)+"></a>





What will be the codeigniter version of this

#2
[eluser]achilleusrage[/eluser]
For security reasons, CodeIgniter is strict (by default) about which characters you can put in your URI strings. See:
http://ellislab.com/codeigniter/user-gui...urity.html

and

http://ellislab.com/codeigniter/user-gui...urity.html

You can allow other characters and even enable query strings but that's at your own risk.

Otherwise, the PHP equivalent to encode characters is:
Code:
urlencode($str);

#3
[eluser]bleu[/eluser]
[quote author="achilleusrage" date="1331301630"]For security reasons, CodeIgniter is strict (by default) about which characters you can put in your URI strings. See:
http://ellislab.com/codeigniter/user-gui...urity.html

and

http://ellislab.com/codeigniter/user-gui...urity.html

You can allow other characters and even enable query strings but that's at your own risk.

Otherwise, the PHP equivalent to encode characters is:
Code:
urlencode($str);
[/quote]


When I am adding
Code:
$str="How are you &x=5";
urlencode($str);

it is giving me this url
Code:
How+are+you+&x=5
and this error
Code:
An Error Was Encountered

The URI you submitted has disallowed characters.


How can I solve this?

The data will come from the database and will then be encoded in the url

#4
[eluser]achilleusrage[/eluser]
Limiting characters in URI's is an important security measure. You should really look into doing something else with the data in your URIs (like, strip special characters and replace whitespace with underscores (_)).

Example: http://yourwebsiteaddress/how_are_you/x/5

But, with that warning, you can allow other characters in your config.php file:

Code:
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify with a regular expression which characters are permitted
| within your URLs.  When someone tries to submit a URL with disallowed
| characters they will get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible.  By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

...if indeed, as the comments above suggest, you are insane. :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.