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
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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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