nkosinathi Posted November 25, 2010 Share Posted November 25, 2010 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 More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 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 Link to comment https://forums.phpfreaks.com/topic/219801-query-string-url-encoding-challenge/#findComment-1139456 Share on other sites More sharing options...
nkosinathi Posted November 25, 2010 Author Share Posted November 25, 2010 Thanks for your query string advice but i am accessing somebody's API with this so its not my decision on human readable url query string . DOing it manually, not sure. Will try this and see what happens. Link to comment https://forums.phpfreaks.com/topic/219801-query-string-url-encoding-challenge/#findComment-1139459 Share on other sites More sharing options...
suma237 Posted November 25, 2010 Share Posted November 25, 2010 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); ?> Link to comment https://forums.phpfreaks.com/topic/219801-query-string-url-encoding-challenge/#findComment-1139462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.