Jump to content

Safe site search via ASCII


l4ci

Recommended Posts

Hey there,

wondering if anyone knows what this topic will be about ;D okay lets start:

 

I have a search function on my site. Basically I do this:

 

if $_POST -> redirect ?search=$_POST

if $_GET['search'] - > sql_query($search);

 

Of course I am working with functions like

mysql_real_escape_string - addslashes - htmlspecialchars , but I have the following problem:

 

when redirecting chars like & % ? ! kill my $_GET var.

 

Which function solves this?

 

My solution:

I convert every char in $_POST into an ascii code -> redirect ?search=$ascii_codes

convert back into $string and do safe search.

 

 

Link to comment
Share on other sites

urlencode()

does the trick

 

anway if someone needs to convert a string into an asci string and back here you go:

 

Convert into ASCII:

$wort = trim(stripslashes($wort));
$c = strlen($wort);

$asci = "";
$i = 0;
while($i<=$c){
	if($i != $c){
		$asci .= ord($wort[$i]);
		if($i+1 != $c){
			$asci .= "_";
		}
	}
$i++;
}

$query = $asci;

 

Convert back:

$asci = trim($asci);
$array = explode("_",$asci);
$string = "";
foreach ($array as $value){
	$string .= chr($value);
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.