brijesh
How To Protect Special Characters in Query String?
1 Answer(s)      4 years and 10 months ago
Posted in : PHP

How To Protect Special Characters in Query String?

Advertisement
View Answers

November 15, 2010 at 1:00 PM


Hi all,

For this purpose you can urlencode() translation function.

Example :

<?php

$string = "This is deepak.";

$url = "my.php?data=" . urlencode($string);
print "<a href=\"$url\">Just Click</a><br>";
if (isset($_REQUEST["data"])) {
   print "URL IS : " . $_SERVER['REQUEST_URI'] . "<br>";
   print "Decoded data is : " . urldecode($_REQUEST["data"]);
}

?>

The output :

Just Click 
URL IS : /my.php?data=This+is+deepak+.
Decoded data is : This is deepak.

Thanks