How to get current URL path in PHP

0 votes

I need to get the path from the URL of the current request. For example, if the current URL is:

"http://www.example.com/example/test/hi.php?randomvariable=1"

I would want this:

"/example/test/hi.php?randomvariable=1"
Sep 1, 2020 in PHP by kartik
• 37,520 points
4,029 views

1 answer to this question.

0 votes

Hello @kartik,

Use

$_SERVER['REQUEST_URI']. 

The URI which was given in order to access this page; for instance, '/index.html'.

Hope it helps!!
Thank you!!

answered Sep 1, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to get base url in laravel using php?

Hello @kartik, You can use the URL facade ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,840 points
17,068 views
0 votes
1 answer

How to get the base domain/url in php?

Hello @kartik, Use SERVER_NAME. echo $_SERVER['SERVER_NAME'] ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,840 points
12,188 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
1 answer

How to get the client IP address in PHP ?

Hello, Here is a code sample of a good ...READ MORE

answered Apr 8, 2020 in PHP by Niroj
• 82,840 points
6,969 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,693 views
0 votes
1 answer

How to Get the full URL in PHP?

Hello @kartik, Have a look at $_SERVER['REQUEST_URI'], i.e. $actual_link = ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,840 points
3,335 views
0 votes
1 answer

How to GET URL parameter in PHP?

Hello @kartik, $_GET is not a function or language ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,840 points
3,907 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