I’m trying send following URL as parameter to php,
I try to read the URL using
$url = $_REQUEST["new_url"];
echo $url;
This works fine for the URLs without any special characters. If I remove #:~: this part of the URL, it works fine too. But, with these characters, it’s breaking and only displays https://boxtext.com/expected-my-list-size-b2b.
I’ve tried to send this using a JSON object, but not helping.
Can anyone suggest a way around please?
I’ve tried to send this using a JSON object, but not helping.
2
Answers
This is solved, Used Javascript to encode the URL before sending to PHP.
I was using encodeURI like below encoded_url = encodeURI(v_url);
so changed that to
encoded_url = encodeURIComponent(v_url);
AJAX call to PHP below,
xmlhttp.open("POST", "php/call.php?long_url=" + encoded_url);
If you want to submit URLs as values in a query you have to
urlencode
them: