Untuk mendapatkan parameter dari string URL di PHP, kodenya adalah sebagai berikut−
Contoh
Demo Langsung
Keluaran
Ini akan menghasilkan keluaran berikut−
Email = example12@domain.comContoh
Mari kita lihat contoh lain −
Demo Langsung
Keluaran
Ini akan menghasilkan keluaran berikut−
Email = demo_[email protected]
Jadi, dalam tutorial ini, kami menyoroti dua fungsi praktis yang memungkinkan mendapatkan parameter dari string URL dengan PHP
When using the http_build_query function to create a URL query from an array for use in something like curl_setopt($ch, CURLOPT_POSTFIELDS, $post_url), be careful about the url encoding.
In my case, I simply wanted to pass on the received $_POST data to a CURL's POST data, which requires it to be in the URL format. If something like a space [ ] goes into the http_build_query, it comes out as a +. If you're then sending this off for POST again, you won't get the expected result. This is good for GET but not POST.
Instead you can make your own simple function if you simply want to pass along the data:
$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.
$ch = curl_init($some_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_url);
curl_exec($ch);
?>
Note that at the final page that processes the POST data, you should be properly filtering/escaping it.