1function strip_param_from_url( $url, $param ) {
2 $base_url = strtok($url, '?'); // Get the base url
3 $parsed_url = parse_url($url); // Parse it
4 $query = $parsed_url['query']; // Get the query string
5 parse_str( $query, $parameters ); // Convert Parameters into array
6 unset( $parameters[$param] ); // Delete the one you want
7 $new_query = http_build_query($parameters); // Rebuilt query string
8 return $base_url.'?'.$new_query; // Finally url is ready
9}
10// Usage
11echo strip_param_from_url( 'http://url.com/search/?location=london&page_number=1',
12 'location' )
1<a href="#" onclick="postLogin()">Log me into this website</a>
2
3<script type="text/javascript">
4function postLogin() {
5 var form = document.createElement("form");
6 form.setAttribute("method", "post");
7 form.setAttribute("action", "http://search.mywebsite.com/login.aspx");
8
9 var params = {checktype: 'uid', user: 'adam', password: 'pass1234', profile: 'dart', defaultdb: 'kts'};
10 for(var key in params) {
11 if(params.hasOwnProperty(key)) {
12 var hiddenField = document.createElement("input");
13 hiddenField.setAttribute("type", "hidden");
14 hiddenField.setAttribute("name", key);
15 hiddenField.setAttribute("value", params[key]);
16
17 form.appendChild(hiddenField);
18 }
19 }
20
21 document.body.appendChild(form);
22 form.submit();
23}
24</script>