Switch to full style
General Articles.
Post a reply

Encoding parameters in URL

Wed Aug 29, 2012 3:35 pm

There are some cases when you are passing parameters via URL you need to encode the parameters values. Many languages have a built in function for URL encoding:
For Python:
Code:
import urllib

print "Get URL : http://codemiles.com/test.py?password=%s" % (urllib.quote_plus(password))

For JavaScript:
Code:
var urlWithParam = "http://codemiles.com/index.php?password=" + encodeURIComponent(password);

For Perl:
Code:
use URI::Escape;

$myURL = sprintf('http://codemiles.com/myPage.php?password=%s',uri_escape($password));

sub encodeParam {
    my $s = shift;
    $s =~ s/ /+/g;
    $s =~ s/([^A-Za-z0-9\+-])/sprintf("%%%02X", ord($1))/seg;
    return $s;
}

$myURL = sprintf('http://codemiles.com/test.php?password=%s', encodeParam ($password)

For ASP.NET:
Code:
String nextPage;
nextPage = "http://codemiles.com/index.php?password=" + Server.UrlEncode(password);

Response.Write("<a href=" + nextPage + ">Submit Page</a>");

For PHP:
Code:
<?php
print '<a href="://codemiles.com/index.php?password=', urlencode($passowrd), '">Next Page</a>';
?>




Post a reply
  Related Posts  to : Encoding parameters in URL
 URL Characters and URL Encoding Values     -  
 session Encoding Data in php     -  
 usage of the meta tag for content encoding     -  
 Reference Parameters     -  
 Function with default parameters     -  
 Send parameters using HTTP GET     -  
 Post parameters using JQuery     -  
 Method Parameters,,,is it by value or reference???     -  
 get url, title and url sent parameters with JQuery     -  
 Extracting Parameters from GET or POST Request     -