Home php PHP - get page url

PHP – get page url




A php script is executed on the page.
Page url like: site.com/razdel/index.html
The script is in the root, in a separate folder.
Hints like $ _SERVER ['REQUEST_URI'] lead to a script file
How to in php get the html page URL?

Any manipulation of files, their location and structure is rejected.

Answer 1, authority 100%

echo 'http: //'.$_SERVER [' HTTP_HOST ']. $ _ SERVER [' REQUEST_URI '];

Answer 2, authority 40%

From here I took: https://stackoverflow.com/questions/2820723/ how-to-get-base-url-with-php

// site URL
$ url = 'http'. ((isset ($ _ SERVER ['HTTPS']) & amp; & amp; $ _SERVER ['HTTPS']! = 'off')? 's': ''). ': //';
$ url = $ url. $ _SERVER ['SERVER_NAME']. $ _SERVER ['REQUEST_URI'];
define ('URL', $ url);

Answer 3

Returns what is needed $ _SERVER ['HTTP_REFERER']

Answer 4

header ("location: http: //site.com/razdel/index.html");

It seems to help.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions