How can I get URL (with some parameters)? [duplicate] - php

This question already has answers here:
Get URL query string parameters
(11 answers)
Closed 6 years ago.
I have a form on page, with url like this:
site.com/form.index.html?ref=https://login....
And I get page URL via this code:
http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]
But as result I get not full URL, just this:
site.com/form.index.html
How can I get full URL?

You want to add the query string:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$_SERVER[QUERY_STRING]";
Additionally, you may replace the http bit with $_SERVER[REQUEST_SCHEME]:
"$_SERVER[REQUEST_SCHEME]://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$_SERVER[QUERY_STRING]"

Related

Get part of string PHP [duplicate]

This question already has answers here:
PHP - parse current URL
(6 answers)
Closed 2 years ago.
How to get a part of string using PHP?
I have a string like this.
https://test-app.com/admin/api/2019-10/orders.json?limit=2&page_info=eyJpZHMiOiIyMDY3MTczMTEzOTg3LDIwNjU0ODU0MzA5MTUsMjA2NTQ3OTI3MDUzMSwyMDYyODE3MzI5MjgzIiwibGFzdF9pZCI6MjA2NTQ4NTQzMDkxNSwibGFzdF92YWx1ZSI6IjIwMjAtMDMtMTcgMTg6MTc6NTkiLCJkaXJlY3Rpb24iOiJuZXh0In0
I want only the link.. like this
orders.json?limit=2&page_info=eyJpZHMiOiIyMDY3MTczMTEzOTg3LDIwNjU0ODU0MzA5MTUsMjA2NTQ3OTI3MDUzMSwyMDYyODE3MzI5MjgzIiwibGFzdF9pZCI6MjA2NTQ4NTQzMDkxNSwibGFzdF92YWx1ZSI6IjIwMjAtMDMtMTcgMTg6MTc6NTkiLCJkaXJlY3Rpb24iOiJuZXh0In0
That's not just a string it's a URL so use URL and path functions:
$parts = parse_url($str);
echo basename($parts['path']).$parts['query'];

How to extract path url using PHP [duplicate]

This question already has answers here:
PHP Parse URL From Current URL
(6 answers)
Closed 3 years ago.
How can I extract path in url using php ?
example :
text input = https://drive.google.com/open?id=1OJOZBBUCa5SsmUF3UdGJCk7A4t2kAHVr
output = 1OJOZBBUCa5SsmUF3UdGJCk7A4t2kAHVr
You can use $_GET['id'].
Or $_SERVER['QUERY_STRING'] to get all the parameters.

replace particular value from url [duplicate]

This question already has answers here:
PHP, Delete parts of a URL variable [duplicate]
(3 answers)
Closed 4 years ago.
I want to replace '/50' with URL.my URL is
http://localhost/CI/admin/pcustomer/cprofile/50?customer=18267&mobile=&nearby=
I want url as
http://localhost/CI/admin/pcustomer/cprofile?customer=18267&mobile=&nearby=
From that little info in your question, this seems to be the simplest way to achieve "I want to replace '/50' with URL"
$url = str_replace('/50', '', 'http://localhost/CI/admin/pcustomer/cprofile/50?customer=18267&mobile=&nearby=');

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

Categories