TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 04-25-2008, 09:36 PM   #1 (permalink)
The Contributor
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 91
Thanks: 11
EyeDentify is on a distinguished road
Default Prototype and URL encodeded strings

Sorry if this is in the wrong place but i think the root of the problem lies in the JS part.

I will try to explain in the easiest way my problem.

First, i´m using the latest Prototype JS framework (1.6.0.2).
I´m having no problem getting it to work except for the darn URL encode bit.

And just to avoid any confusion about 'Kat' in the code.
I´m using that word because in swedish 'Cathegorys' would be 'Kateogorier'.

Now my very simple JS code to accomplish a AJAX GET call is:

Code:
function MyLinkKat(MyUrl, MyKat)
{

var MyUrl;
var MyKat; //This is were my cathegory comes

	new Ajax.Request(MyUrl, {
	  contentType: 'application/x-www-form-urlencoded',
	  encoding: 'UTF-8',
	  method: 'get',
	  parameters: '?kat=' + MyKat + '',
	  onCreate: function(transport)
	  { 
	  	var MyStatusText = $('MyStatusDiv');
	  	new Ajax.Updater(MyStatusText, 'ajax_loader.php');
	  },
	  onSuccess: function(transport)
	  { 
	  	var MyResponseText = $('MyResponseDiv');
	  	MyResponseText.update(transport.responseText);
	  },
	  onComplete: function(transport)
	  { 
	  	var MyStatusText = $('MyStatusDiv');
	  	MyStatusText.update('');
	  }
	});
}
I´m thinking something goes wrong at the 'parameters' option in the Ajax.Request.
What do you think ?

I´m calling this code like this:

Code:
<A HREF="javascript:MyLinkKat('ajax_links.php', 'Bloggs & Misc')">Bloggs & Misc</A>
Now my problem seems to be that this string 'Bloggs & Misc' don´t seem to be URL encoded when transported throug the JavaScript and when it reaches the 'ajax.php' script nothing matches cause i only get 'Bloggs' left.

Now i thought to myself, this is easy to fix. So i tryed this aproach:
Code:
<A HREF="javascript:MyLinkKat('ajax_links.php', '<?PHP echo(urlencode("Bloggs & Misc")); ?>')">Bloggs & Misc</A>
But that didn´t work either.

For the sake of argument let´s say that the following code is in the receiving script:
PHP Code:
<?PHP
$sql 
"SELECT * from blogg_links WHERE kategori='" utf8_decode($_GET['kat']) . "'";
?>
Should i try using urlencode() inside the utf8_decode() function on the $_GET['kat'] variable ?

Do you have any suggestions or ideas to what i could change to make this work, or do you want any other information to help me resolve this mather don´t hesitate to ask.

It might be a simple solution that i haven't thought about in my frustration.

Hope you get what i´m getting at.

It´s kinda late and think i´m gonna give this a break for tonight.

Cheers :)

-----------------------------------------
Update:

Well i had some sleep and came up with this temporary solution that works for me. Im using the following PHP functions that i came up with to do some "Ajax Encoding" and "Ajax Decoding" as i like to call it. Wich means i simply replace some chars like 'spaces' and '&' signs with other safe chars that wont 'get lost' in the transport. i made a Encode and Decode function.

Here it is:
PHP Code:
<?PHP
function ajaxEncode($string)
{
    
$target_array[] = ' ';
    
$target_array[] = '&';

    
$replace_array[] = '_';
    
$replace_array[] = 'och';

    
$string str_replace($target_array$replace_array$string);
    return 
$string;
}
function 
ajaxDecode($string)
{
    
$target_array[] = '_';
    
$target_array[] = 'och';

    
$replace_array[] = ' ';
    
$replace_array[] = '&';

    
$string str_replace($target_array$replace_array$string);
    return 
$string;
}
?>
But i would still like to get some explaination if there is one to why my orignial problem existed if someone has an answer?

Cheers again :)
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.

Last edited by EyeDentify : 04-26-2008 at 09:04 AM. Reason: Temporary Solution
EyeDentify is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:55 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0