john
john

Reputation: 3

get URL in php IN INCLUDE FILE

i have some problem i try to get the uri in php.

I'm using:

 $_SERVER['REQUEST_URI']

It works just fine if i do it in the index.php, but, i NEED to get the url in a include file, but, when i do it, it takes the FILE adress, i mean, it shows something like this

adress bar: www.webpage.com/index.php

$_SERVER['REQUEST_URI'] output: webpage/includefile.php

I am explaining myself here? Thanks!

Upvotes: 0

Views: 1797

Answers (3)

Gabb
Gabb

Reputation: 11

Found this whilst trying to solve the same issue. My solution that worked is to use $_SERVER['HTTP_REFERER'] This worked well in that it also included the parameters (e.g. ?this=that&foo=bar)

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

Maybe somewhere in your code (or in another include file) the value is overwritten.

Upvotes: 0

Basic
Basic

Reputation: 26766

How are you including the file? If it's being included via an HTTP reference then it's actually being served as a page and the functionality you are seeing is correct. If the include path is a local file, you shouldn't be seeing this behaviour

Upvotes: 1

Related Questions