GET a URL parameter with PHP [duplicate] - php

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.

Related

$_GET not passing results containing value containing '#' [duplicate]

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"

How to obtain part of the url with php [duplicate]

This question already has answers here:
How can I get parameters from a URL string?
(12 answers)
Closed 6 years ago.
I am coming up with a way to display user profiles. Right now I am able to insert the user_id into the url when going to a user's profile, but I am unsure of how to get the user_id from the url.
So at the end of the url I have this:
profile?user=41
I just want to be able to get the 41 (please note this number will change per profile) and then set it to a variable.
How would I do this?
<?php
echo $_GET['user'];
?>
all the parameters of the url are stored in the $_GET variable...
The parameter that are in your URL can be retrieved with the
predefined variable:
<?php
//$userId = $_GET["pramName"];
$userId = $_GET["user"];
// or
// using the $_REQUEST variable
?>

How I redirect dynamic url with query string in php? [duplicate]

This question already has answers here:
How do I make a redirect in PHP?
(34 answers)
Closed 6 years ago.
I need to redirect dynamic URL like this "https://test.com?user=abc#gmail.com" to "https://test.com"
If I understand correctly, this URL is coming dynamically with a query string. And you want to remove the query string portion and redirect to this modified URL.
Let's assume the dynamic URL is stored in a variable $url.
Try this:
$url = "https://test.com?user=abc#gmail.com";
$modified_url = strstr($url, "?", true); // Remove the query string, which results in https://test.com
header("location:".$modified_url); // Redirect to the modified URL.
You can store the dynamic part in a variable and use the header() function to redirect your user.
$dynamicPart = "someguy#somedomain.com";
header("Location: https://test.com/index.php?username=".$dynamicPart);
exit;

What to parameter value from returning url in php [duplicate]

This question already has answers here:
GET URL parameter in PHP
(7 answers)
Closed 7 years ago.
I have a client url[www.mysite.com/page.aspx]
when we put this url in browser then it revert the automatically
with this url
[www.mysite.com/page.aspx?|&CC=121&DD=123&AA=323|&CC=321&DD=555&AA=000]
Now we want to fetch that parameter value in php page through php or jquery.
Kindly Help and give the best suggestions.
You can simply use GET
$cc = $_GET['CC'];
$dd = $_GET['DD'];
You can access those values using $_REQUEST or $_GET

Codeigniter Retrieving Chargify Return parameters [duplicate]

This question already has answers here:
CodeIgniter PHP Framework - Need to get query string
(12 answers)
How can I read a QueryString in CodeIgniter?
(3 answers)
Closed 9 years ago.
Using Chargify with Codeigniter framework. On completion of signup with Chargify, the return URL can be set with parameters. It seems that these parameters can only be returned ?id=123&ref=321. With Codeigniter, how do I grab those return paramenters?
http://www.website.com/confirmation?id=3163255&ref=5159c58278a1f
CodeIgniter, by default, destroys the $_GET variable that one would usually use to access the parameters in a URL.
This line will parse the URL and populate the $_GET array with the URL's parameters. It's useful for when you want to selectively use the $_GET array in a CodeIgniter project, rather than having to enable CodeIgniter's query strings, which would be globally and continually active.
parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
It can then be accessed as you would normally access an array, for example:
$id = $_GET['id'];
$ref = $_GET['ref'];

Categories