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"
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:
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"]);
This question already has answers here:
GET URL parameter in PHP
(7 answers)
Get the full URL in PHP
(27 answers)
Closed 6 years ago.
I would like to capture the lang variable and then translate the page based on this variable.
global $jwp_lang;
$url = $_SERVER["REQUEST_URI"];
echo $url;
for example if the url contains http://localhost/about/?lang=fr I would like to capture this value.
You can easily capture the value of lang variable using php Super Global variable $_GET :
$lang = $_GET['lang'];
echo $lang;
It is better to pass the URL parameters using add_query_var, and get the parameter using get_query_var.
Because, they can handdle the set, and get of multiple parameters, and is the recommended way of getting URL passed as parameters.
This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I have a URL
http://localhost/ifocus/v3/services.php#nav-section2
I want to get hashtags from URL, EX : if the URL contains "#" so capture it via PHP
nav-section2
When i do
echo $_SERVER['REQUEST_URI'];
// Output
/ifocus/v3/services.php
You can't detect the hash parameter of the URL in PHP, you would need to use JavaScript.
You could make a jquery call to php which passes the hash data (window.location.hash) to a PHP script as a URL parameter and return TRUE/FALSE though.
You can not capture this content for that you need js(client side script)