Jump to content

Query string URL encoding challenge


nkosinathi

Recommended Posts

Hi All

Thanks in advance for your help.

 

I want to have to following query string Type=myparam&Username=dazd&Password=nk98830&id=0&Cols_Returned=numfrom,sentdata

 

But my code returns the following

Type=myparam&Username=dazd&Password=nk98830&id=0&Cols_Returned=%2F%22numfrom%2F%22%2C%2F%22sentdata%2F%22

 

Below is the code:

$data= array(

"Type"=> "myparam",

"Username" => "dazd",

"Password" => "nk98830",

"id" => "0",

"Cols_Returned" => '/"numfrom/",/"sentdata/"'

 

) ; //This contains data that you will send to the server.

$data = http_build_query($data); //builds the post string ready for posting

echo "The Query String is                  ";

echo $data;

 

 

Regards

Link to comment
https://forums.phpfreaks.com/topic/219801-query-string-url-encoding-challenge/
Share on other sites

Why would you want a human readable url query string with passwords and usernames? This is very vulnerable for malicious visitors!  its not smart, especially with passwords. Dont do that! Use $_POST instead!

 

IF you still want this.... Dont use http_build_query as this will return a encoded url query string.

You have to build this manually like

page.php?Type=myparam&Username=dazd&Password=nk98830&id=0&Cols_Returned=numfrom,sentdata

 

replace the values with vairables so it will be dynamically

please refer this article

 

http://php.net/manual/en/function.http-build-query.php

<?php

$post_url = '';

foreach ($_POST AS $key=>$value)

    $post_url .= $key.'='.$value.'&';

$post_url = rtrim($post_url, '&');

?>

 

You can then use this to pass along POST data in CURL.

 

<?php

    $ch = curl_init($some_url);

    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_url);

    curl_exec($ch);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.