How to get request string without GET arguments

0 votes
Is there a simple way to get the requested file or directory without the GET arguments? For example, if the URL is http://example.com/directory/file.php?paramater=value I would like to return just http://example.com/directory/file.php. I was surprised that there is not a simple index in $_SERVER[]. Did I miss one?
Nov 14, 2020 in PHP by kartik
• 37,520 points
3,081 views

1 answer to this question.

0 votes

Hello @kartik,

You can use $_SERVER['REQUEST_URI'] to get requested path. Then, you'll need to remove the parameters...

$uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);

Then, add in the hostname and protocol.

echo 'http://' . $_SERVER['HTTP_HOST'] . $uri_parts[0];

Hope it helps!!
Thank You!!

answered Nov 14, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to get parameters from a URL string?

Hello @kartik, You can use the parse_url() and parse_str() for that. $parts = ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,840 points
865 views
0 votes
1 answer

How to get the http headers from current request in PHP?

Hello, Try this code: if (!function_exists('getallheaders')) { ...READ MORE

answered Nov 23, 2020 in PHP by Niroj
• 82,840 points
2,786 views
0 votes
0 answers

Does the string "php?id=1" within a http GET request mean there is necesseraly an sql request to a back-end database?

You can use Google dorks like "inurl:.php?id=" ...READ MORE

Aug 6, 2022 in PHP by Kithuzzz
• 38,000 points
2,944 views
0 votes
0 answers

How to send a GET request from PHP?

I intend to use PHP to fulfil ...READ MORE

Aug 7, 2022 in PHP by Kithuzzz
• 38,000 points
475 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,696 views
0 votes
1 answer

How Do I Get the Query Builder to Output Its Raw SQL Query as a String?

Hello @kartik, Use the toSql() method on a QueryBuilder instance. DB::table('users')->toSql() would return: select * ...READ MORE

answered Jul 22, 2020 in PHP by Niroj
• 82,840 points
1,085 views
0 votes
1 answer

How to get the request parameters in symfony2

Hello @kartik, The naming is not all that ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,840 points
3,155 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP