identify by php the path of the page

identify by php the path of the page

am 30.09.2007 23:39:37 von artev

if I have a file myfile.php (the dir are more)

http://SITE/A/B/myfile.php

is possible insert in the page a code that write the path where it is =
http://SITE/A/B/

and also must recognize if its url change example http to https
https://SITE/A/B/myfile.php
it write
https://SITE/A/B/

Re: identify by php the path of the page

am 01.10.2007 06:32:22 von Shion

artev wrote:
> if I have a file myfile.php (the dir are more)
>
> http://SITE/A/B/myfile.php
>
> is possible insert in the page a code that write the path where it is =
> http://SITE/A/B/
>
> and also must recognize if its url change example http to https
> https://SITE/A/B/myfile.php
> it write
> https://SITE/A/B/

If you use a decent web server, then you can use mod_rewrite to make the web
server load a different file than what what the browser has requested.

--

//Aho

Re: identify by php the path of the page

am 01.10.2007 14:53:32 von artev

I explained better my problem (localhost in production will be NAMESITE)
If I am in http://localhost/A/test.php

I want in php a code (or function) that print:
http://localhost/A/

so it recognize automatically the url

I tested functions:
HTTP_HOST but print only localhost
SERVER_NAME but print only localhost
PHP_SELF not print all and insert also file's name (I not want)
/A/test.php

dirname($HTTP_SERVER_VARS['PHP_SELF']); not print all /A


I can write so (semplified the merge):
http:// + SERVER_NAME + dirname PHP_SELF
but remain problems that I must know when I am in https so I can change
the first part http in https;

and is better use SERVER_NAME or HTTP_HOST for recognize SITE (localhost)


is there a function that to do all?

Re: identify by php the path of the page

am 02.10.2007 06:37:55 von Aaron Saray

On Oct 1, 7:53 am, artev wrote:
> I explained better my problem (localhost in production will be NAMESITE)
> If I am inhttp://localhost/A/test.php
>
> I want in php a code (or function) that print:http://localhost/A/
>
> so it recognize automatically the url
>
> I tested functions:
> HTTP_HOST but print only localhost
> SERVER_NAME but print only localhost
> PHP_SELF not print all and insert also file's name (I not want)
> /A/test.php
>
> dirname($HTTP_SERVER_VARS['PHP_SELF']); not print all /A
>
> I can write so (semplified the merge):
> http:// + SERVER_NAME + dirname PHP_SELF
> but remain problems that I must know when I am in https so I can change
> the first part http in https;
>
> and is better use SERVER_NAME or HTTP_HOST for recognize SITE (localhost)
>
> is there a function that to do all?

What if you did this:

function getBaseUrl()
{
if (empty($_SERVER['HTTPS'])) {
//means its either not set or has no value - this will be
populated if its an SSL request
$url = 'http://';
}
else {
$url = 'https://';
}
$url .= dirname($_SERVER['REQUEST_URI']);
}

I wonder if that will work?