This question already has answers here:
Is it possible to preserve plus signs in PHP $_GET vars without encoding?
(7 answers)
Apache mod_rewrite %2B and plus (+) signs
(1 answer)
Closed 3 years ago.
How can I get the value from URL without replacing + sign with spaces?
URL: https://example.com/platform?id=xxtMEzBG56F3Z2Z+w1VT+g==
Currently, when I try to get variable in PHP by $_GET['id'] it automatically replaces + with space. How can I get the real value here?
The value I am getting is xxtMEzBG56F3Z2Z w1VT g==, what I want is xxtMEzBG56F3Z2Z+w1VT+g==
You can use $_SERVER with QUERY_STRING
echo str_replace('id=','',$_SERVER["QUERY_STRING"]);
Related
This question already has answers here:
PHP - Plus sign with GET query
(6 answers)
Obtain $_GET value have plus ('+') Character in PHP
(4 answers)
Is it possible to preserve plus signs in PHP $_GET vars without encoding?
(7 answers)
Closed 6 months ago.
I have a URL string like https://example.com/path/?welcome_screen=1&email_address=something+else#example.com
In PHP, I call <?php echo $_GET['email_address']; ?>
Which produces something else#example.com
Specifically, a space instead of the + in the email address.
Is this expected?
If so, is there a way to prevent this from happening in the echo code above?
Or should it be handled when collecting the email address somehow?
Yes, + is one way to represent a space character in a URL. PHP automatically URL-decodes the value when it creates the $_GET data and converts it to a space, as it assumes that's what the value is supposed to represent in the raw URL.
No, it's too late by then.
Yes, you should URL-encode the value before including it in the URL, so that the + is not treated as a special character. If PHP is generating the URL, you'd use the urlencode() function. Most other programming languages have equivalent built-in functions.
This question already has answers here:
How can I properly URL encode a string in PHP?
(6 answers)
Closed 12 months ago.
I want to create a redirect in PHP where I want to pass + sign as %2B in URL but whenever, I'm using header("Location: url ") . It is passing the + sign as +, So at the end server, after decoding it is showing a blank space instead of showing + sign.
<?php
echo $eqn=$_GET['eqn'];
$ord=$_GET['ord'];
header("Location: http://example.com/$eqn")
?>
Basically, I've created a HTML form where I am passing data to the following php page, Here I want to redirect to a url like http://example.com?i0=encoded-value-required/aa.
And here in the encoded-value-required parameter, I want to pass the + sign as %2B in the header location.
Like ADyson wrote you should use urlencode.
$eqn = urlencode($_GET['eqn']);
This question already has answers here:
PHP - Plus sign with GET query
(6 answers)
When should space be encoded to plus (+) or %20? [duplicate]
(5 answers)
Closed 3 years ago.
First of all thanks in advance to everyone helping me out with my question.
I've got a base64_encoded string that looks like:
$_GET['val']='8AH1Oc+gqwjMPyyAL+PIu2neFF5C+bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd+7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX+I+qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy+K9ABLBqUta9+0Mk3JCg+wO/WA2Bh06M0n4ux+qk=';
but when im trying to get the same variable to decode it i recieve it with pluses removed:
$string=$_GET['val'];
echo $string; // either echo $_GET['val']; output will be '8AH1Oc gqwjMPyyAL PIu2neFF5C bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd 7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX I qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy K9ABLBqUta9 0Mk3JCg wO/WA2Bh06M0n4ux qk='
Could somebody please explain why does it happen?
This question already has answers here:
What is the equivalent of JavaScript's encodeURIcomponent in PHP?
(5 answers)
urlencode vs rawurlencode?
(11 answers)
Closed 4 years ago.
I save a web page edited by users in our app backend
in js : encodeURIComponent returns this
%3C!--%20saved%20from%20url%3D(0077)https%3A%2F%2Fwww.w3schools.com%2Fw3css%2Ftryw3css_templates_gourmet_catering.htm%23about
in php : urldecode returns this
<!-- saved from url=(0077)https:\/\/www.w3schools.com\/w3css\/tryw3css_templates_gourmet_catering.htm#about
so far so good....
now, when I fetch the data from the db and reencode it in php urlencode returns this :
%3C%21--+saved+from+url%3D%280077%29https%3A%2F%2Fwww.w3schools.com%2Fw3css%2Ftryw3css_templates_gourmet_catering.htm%23about
so it ends up in JS beeing decoded with + all over the place :
<!--+saved+from+url=(0077)https://www.w3schools.com/w3css/tryw3css_templates_gourmet_catering.htm#about
1 - yes I could just replace the + but I feel I am doing something wrong
2 - why does encodeurl do that if it is not compatible with js decodeURIcomponent ?
regards
This question already has answers here:
Encoding javascript url to pass #(hashtag)
(3 answers)
How to pass parameters with hash in PHP
(4 answers)
How to pass a hash tag (#) with an address bar variable ?searchTerm=#JustKeepGoing
(1 answer)
Closed 5 years ago.
I am passing a value for eg : http://example.com/channel.php?channel=#football
Note : #football is an hashtag , # is used as a reference to hashtag
But on the channel.php page the value '#football' is not getting using the below code.
<?
if (isset($_GET['channel']) && $_GET['channel'] != "") {
$channel = $_GET['channel'];
}
?>
The # symbol ends the request part and starts the hash part of the URI, it is not sent to the server. Use encodeURIComponent to encode hash and decode it back on the back-end before processing the request. So your URI should be something like this:
"http://example.com/channel.php?channel="+encodeURIComponent("#football")
// gives
"http://example.com/channel.php?channel=%23football"