Welcome Guest, Not a member yet? Register   Sign In
problem with percentage in url
#1

[eluser]Stjepan[/eluser]
So, i'm working on this site that should be able to search trough database of names and one of things that are "must have" is that ppl can copy paste search urls so they can use em later on or save em and send to other ppl.

Anyway, everything worked fine until i inserted names with "&" in em (like Jack&John; etc.)
Problem is that once i urlencode em i get "Jack&John, which is perfectly ok with me (search function would urldecode em back to original state), but codeigniter is giving me this message when i try to use it in URL:

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

Only thing that could be disallowed is percentage character.

I checked my config file and this is allowed url char list stuff:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\čČćĆšŠđĐžŽ-';

I dont know what to do...i need those percentages to work in my url's....pls help
#2

[eluser]mi6crazyheart[/eluser]
Try these 2 function...

Code:
function textEncryption($textToEncrypt)
{
    for($i = 0; $i < strlen($textToEncrypt); $i++)
    $encryptedText .= str_pad(base_convert(ord($textToEncrypt[$i]), 10, 16), 2, '0', STR_PAD_LEFT);
    return $encryptedText;
}        

function textDecryption($encryptedText)
{
    if (strlen($encryptedText) % 2 == 1)
   $encryptedText = '0'.$encryptedText;
  
   for($i = 0; $i < strlen($encryptedText); $i += 2)
   $decryptedText .= chr(base_convert(substr($encryptedText, $i, 2), 16, 10));

    return $decryptedText;
}

First function is for encryption. Which u can use to encrypt u'r text before using that in u'r URL. Then at the receiving end u can use 2nd function to decrypt that encrypted name to get the original name. Hope that will work for u...
#3

[eluser]Stjepan[/eluser]
Ah thanks mate. I tought i was just stupid and there is some "build in" way to do this.
I'll just put this two nice functions of yours in my lib and fire em up when needed.
Thanks.
#4

[eluser]pickupman[/eluser]
I just make a md5 of the search string. Store the search string and the md5 string in the DB. Then redirect to /search/(md5) string. Then you can use pagination too. That's how this forum is done as well.
#5

[eluser]Stjepan[/eluser]
md5 idea isnt bad at all but it gives someaditional database load which i'm not willing to take on this server but ill keep it in mind for other projects.
Code/decode functions work great (i just tested em on my site) so thanks once again!
#6

[eluser]ClaudioX[/eluser]
how are you using the first mi6crazyheart's function? when the user do the search the data has to be accurately converted? Another: the implications are very serious, if we change the URI class to work with REQUEST_URI, PATH_INFO instead of?

Update:
In URI class change the function _explode_segments for that:
Code:
function _explode_segments()
{
    $aux = str_replace(" % 2 F ", "/", urlencode($this->uri_string));
    foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $aux)) as $val)
    {
        // Filter segments for security
        $val = trim($this->_filter_uri($val));
        if ($val != '')
        {
            $this->segments[] = $val;
        }
    }
}
" % 2 F " whitout backspaces..


Obs: I'm just tryng here... Big Grin

Stjepan: This regex maybe works with yours characters
$config[‘permitted_uri_chars’] = ‘a-z à-Ú 0-9~%.:_\-’;
#7

[eluser]Stjepan[/eluser]
I don't really know what do you mean about "how" do i use it. I get what user types in, use that function to encrypt it and than i go to index.php/homepage/search/encryptedstring
There, search function decrypts it and does it's magic (loads libs that do database searches and stuff).
That enables my users to copy/paste/save search url and use it later to get same resaults (if database doesn't change of course).
Only thing i had to change is that i had to define "$encryptedText" and "$decryptedText" before using it because i got some errors about that.

And only downside of those functions is that search strings are not "readable" in no way. I'd rather have it something like: index.php/homepage/search/jack/john
It's not 100% readable but it's way way more readable than any other solution.

As for rest of your post....if i understand it correctly (i'm really tired), you are proposing changes that would enable percentages in url? That would be great! I'll give it a try 1st thing in the morning once i get to work!

P.S Sorry if u wrote something really stupid...i am really really tired Big Grin
#8

[eluser]ClaudioX[/eluser]
Dont worry, we are 2 ^^

My english is poor (duh!), sorry for that.

So, i change the first approach.. (urlencode is not the correct way), i realized:

$aux = str_replace("&", "/", $this->uri_string);

but that only fix the char "&"... -.-' (and mainly, i dont estimate how dangerous it can be)

But... what im tryng to say at beginning, about "how":

1 - user see the form;
2 - write "Kevin & Clay";
3 - submit;
? - where you run the function "textEncryption"??? ^^

Thx!
#9

[eluser]Stjepan[/eluser]
Simple solution to that.
Search function detects if ther's 3rd url string or submited data. If tehre is a string it decrypts it and does it's work, if not, it searches for submited POST data, encypts it and than redirects to itself with new encrypted url.
Maybe it's not as "clean" solution as it can be but it's working perfectly.




Theme © iAndrew 2016 - Forum software by © MyBB