PDA

View Full Version : Need help with URL encoding


jeephp
07-14-2005, 11:27 PM
Hi,
I need some help with URL encryption or something similar. For example I have a URL http://www.myurl.com/search.php?iu=321xw1&di=wswe675511&v1=y&u=12qazxq but I do not want it to be displayed with the parameters rather I would like it to be displayed as http://www.myurl.com/search.php?id=eru3893Xwweu327zsdh347ueir3948

What is the best and the most secure way to do this in PHP, I am developing the site on Windows 2003 Enterprise Server Platform and hosting in IIS 6.0.

Does PHP have some inbuilt function to do this or I would have to use a 3rd party tool for this.

Any advice on this would be highly appreciated.

Thanks

christi
11-21-2005, 08:09 AM
<?
$url = "http://www.myurl.com/search.php?";
echo "<b>original url:</b> $url<br>";
$query = "iu=321xw1&di=wswe675511&v1=y&u=12qazxq";
echo "<b>original query:</b> $query<br>";
$my_encoded_query = base64_encode($query);
echo "<b>encoded query:</b> $my_encoded_query<br>";
$url .= "$my_encoded_query";
echo "<b>resulting URL:</b> $url<br>";
$my_decoded_query = base64_decode($my_encoded_query);

echo "<b>decoded query (same as original):</b> $my_decoded_query<br><br>";
// to get passed values:
echo "<b>original passed variables:</b><ul>\n";
$mystrings = explode("&", $my_decoded_query);
if(is_array($mystrings)) {
foreach($mystrings as $field) {
$data = explode("=",$field);
$key = $data[0];
$value = $data[1];
echo "<li> $key: $value<br>";
}
}
echo "</ul>\n";
?>