Url Encoded Forward Slashes Breaking My Codeigniter App

Why Does url-encoding the first slash after the domain break the url?

The / is a reserved character. It’s not equivalent to %2f. If you need the slash without its defined meaning, you’d use the encoded form.

See RFC 3986: "Reserved Characters":

The purpose of reserved characters is to provide a set of delimiting
characters that are distinguishable from other data within a URI.
URIs that differ in the replacement of a reserved character with its
corresponding percent-encoded octet are not equivalent. Percent-
encoding a reserved character, or decoding a percent-encoded octet
that corresponds to a reserved character, will change how the URI is
interpreted by most applications.

The reason why the mentionend URL still works if you don’t use the reserved char / for the second slash: their CMS simply looks for the ID part in the URL. So you can add whatever you want to the URL, e.g. the following should still work:

http://dottech.org/95285/hey-this-URL-got-featured-at-stackoverflow

(However, it seems that it still has to be / or %2f in their case.)

If you try it with a Wikipedia article, it redirects to the front page:

http://en.wikipedia.org/wiki%2fStack_Overflow

Codeigniter, sending data with url

Hey Man just change your config.php
put this on on your permitted chars

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

you can variate depending on what you need

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

How do you pass a URL into a CodeIgniter controller?

use base64_encode() and base64_decode() to encode/decode the url, but you may need to add more character in your permitted uri config.

Urlencode forward slash 404 error

Since there is a slash / in the parameter, this is getting interpreted as a path name separator.

The solution, therefore, is to replace all occurrences of a slash with something that doesn't get interpreted as a separator. \u2044 or something. And when reading the parameter back in, change all \u2044s back to normal slashes.

(I chose \u2044 because this character looks remarkably like a normal slash, but you can use anthing that would never occur in the parameter, of course.)

url with multiple forward slashes, does it break anything?

HTTP RFC 2396 defines path separator to be single slash.

However, unless you're using some kind of URL rewriting (in which case the rewriting rules may be affected by the number of slashes), the uri maps to a path on disk, but in (most?) modern operating systems (Linux/Unix, Windows), multiple path separators in a row do not have any special meaning, so /path/to/foo and /path//to////foo would eventually map to the same file.

An additional thing that might be affected is caching. Since both your browser and the server cache individual pages (according to their caching settings), requesting same file multiple times via slightly different URIs might affect the caching (depending on server and client implementation).

Encoding a email address that can be used as part of a URL in codeigniter

try using bin2hex() and hex2bin() function,

<?php
function hex2bin($str)
{
$bin = "";
$i = 0;
do
{
$bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
$i += 2;
} while ($i < strlen($str));
return $bin;
}

$str = 'email@website.com';

$output = bin2hex($str);
echo $output . '<br/>';

echo hex2bin($output);

?>

Asynch Page Call From a Bookmarklet with CodeIgniter

Codeigniter unsets $_GET but you can get the data from the query string. It is a little inefficient because PHP will probably end parsing the query string twice, but it should work:

parse_str($_SERVER['QUERY_STRING'], $get);
print_r($get);

All the GET variables should be accesible in the variable $get. See parse_str() documentation for some more information.


As an alternative you could url-encode the current URL and append it to what you are requesting e.g.

var url = 'http://example.com/bookmarklet/' 
+ encodeURIComponent(window.location);

Then in Codeigniter do something like:

//you might have to call urldecode() on this value 
$url = $this->uri->segment(0);

but you may find you then have this problem



Related Topics



Leave a reply



Submit