I want to deliver an URL using Post in HTML/PHP with codeIgniter. So I output my URL’s BASE64-Encoded in a hidden field because the URL is crawled from Googles response Page and nearly any character can be in the URL. As I’ll only use my website on a local server (it’s a SEO tool for my company), I want to enable any character in POST data. I already tried it with $config['permitted_uri_chars'] = '';, but that did not work. I got a ‘Disallowed Key Characters’ error because the Base64 string contains a =.
I’m using CodeIgniter 2
Edit:
Fivell’s answer was right, thanks. So, for interested people, I took the code from Fivell’s link above and wrote a small class for CodeIgniter. To do this, add a file named Base64 to your application/libraries folder and insert this code:
<?php
class Base64 {
function url_encode($url) {
$data = base64_encode($url);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}
function url_decode($url) {
$data = str_replace(array('-','_'),array('+','/'),$url);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
return base64_decode($data);
}
}
?>
then, you can use it in any controller by loading the library via $this->load->library('base64); and en- or decrypt the url via $this->base64->url_encode($url) or $this->base64->url_decode($url)
http://www.php.net/manual/ru/function.base64-encode.php#63543
I think that the problem is standart base64 encoding/decoding in php which is not url safe