Getting actual url? – PHP

  php

Q(Question):

Hi guys…

is there any way to get the actual called URL into a variable? I am not
thinking of
‘http://’.$_SERVER[‘HTTP_HOST’].$_SERVER["SCRIPT_NAME"].’:’.$_SERVER["SERVER_PORT"]

because this obviously does not differ e.g. between http: and https: or
perhaps a user:pass-combo included in the url…

Balu

A(Answer):

In article <c4*************@ID-62676.news.uni-berlin.de>,
Thomas -Balu- Walter <ne*****@b-a-l-u.de> wrote:

Hi guys…

is there any way to get the actual called URL into a variable? I am not
thinking of
‘http://’.$_SERVER[‘HTTP_HOST’].$_SERVER["SCRIPT_NAME"].’:’.$_SERVER["SERVER_P
ORT"]

because this obviously does not differ e.g. between http: and https: or
perhaps a user:pass-combo included in the url…

What I usually do in these circumstances is:

echo ‘<pre>’;
print_r($_SERVER);
echo ‘</pre>’;
die;

And check the output for variables I could use.

JP


Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.

A(Answer):

* Jan Pieter Kunst wrote:

In article <c4*************@ID-62676.news.uni-berlin.de>,
Thomas -Balu- Walter <ne*****@b-a-l-u.de> wrote:

is there any way to get the actual called URL into a variable? I am not
thinking of
‘http://’.$_SERVER[‘HTTP_HOST’].$_SERVER["SCRIPT_NAME"].’:’.$_SERVER["SERVER_P
ORT"]

because this obviously does not differ e.g. between http: and https: or
perhaps a user:pass-combo included in the url…

What I usually do in these circumstances is:

echo ‘<pre>’;
print_r($_SERVER);
echo ‘</pre>’;
die;

And check the output for variables I could use.

This is what I did (I used phpinfo(); though) and did not find a
solution, thats why I asked here…

Balu

A(Answer):

On Wed, 31 Mar 2004 15:08:47 +0000, Thomas -Balu- Walter wrote:

* Jan Pieter Kunst wrote:

In article <c4*************@ID-62676.news.uni-berlin.de>,
Thomas -Balu- Walter <ne*****@b-a-l-u.de> wrote:

is there any way to get the actual called URL into a variable? I am
not thinking of
‘http://’.$_SERVER[‘HTTP_HOST’].$_SERVER["SCRIPT_NAME"].’:’.$_SERVER["SERVER_P
ORT"]

because this obviously does not differ e.g. between http: and https:
or perhaps a user:pass-combo included in the url…

What I usually do in these circumstances is:

echo ‘<pre>’;
print_r($_SERVER);
echo ‘</pre>’;
die;

And check the output for variables I could use.

This is what I did (I used phpinfo(); though) and did not find a
solution, thats why I asked here…

Balu

Would still require concatenation.. but you could use ‘getservbyport’:
$url =
getservbyport($_SERVER[‘HTTP_PORT’]) . ‘://’ . $_SERVER[‘HTTP_HOST’] .
$_SERVER[‘SCRIPT_NAME’] . ‘:’ .
$_SERVER[‘HTTP_PORT’];
This would detect ‘http’ or ‘https’ etc. As for user:pass combos, PHP has
built in SuperGlobals to handle these too (PHP_AUTH_USER etc).
HTH =)

Regards,

Ian


Ian.H
digiServ Network
London, UK
http://digiserv.net/

A(Answer):

In article <pa****************************@bubbleboy.digiserv .net>, Ian.H wrote:

Would still require concatenation.. but you could use ‘getservbyport’:

$url =
getservbyport($_SERVER[‘HTTP_PORT’]) . ‘://’ .
$_SERVER[‘HTTP_HOST’] .
$_SERVER[‘SCRIPT_NAME’] . ‘:’ .
$_SERVER[‘HTTP_PORT’];

This would detect ‘http’ or ‘https’ etc. As for user:pass combos, PHP
has
built in SuperGlobals to handle these too (PHP_AUTH_USER etc).

getservbyport() just guesses the port by e.g. something like
/etc/services? So if you have a testserver running on port 23 (you never
know what wierd things admins do) it will report "telnet"?

Nice idea, but still a little "luck" is needed to make that work
globally.

Balu

A(Answer):

Thomas -Balu- Walter wrote:

In article <pa****************************@bubbleboy.digiserv .net>, Ian.H wrote:

Would still require concatenation.. but you could use ‘getservbyport’:

$url =
getservbyport($_SERVER[‘HTTP_PORT’]) . ‘://’ .
$_SERVER[‘HTTP_HOST’] .
$_SERVER[‘SCRIPT_NAME’] . ‘:’ .
$_SERVER[‘HTTP_PORT’];

This would detect ‘http’ or ‘https’ etc. As for user:pass combos, PHP
has
built in SuperGlobals to handle these too (PHP_AUTH_USER etc).

getservbyport() just guesses the port by e.g. something like
/etc/services? So if you have a testserver running on port 23 (you never
know what wierd things admins do) it will report "telnet"?

Nice idea, but still a little "luck" is needed to make that work
globally.

OK… I’ve been watching this thread hoping that I’d snag a better
solution, but this is what I have been using:

function getThisUrl(){
if(isset($_SERVER[‘HTTPS’]) && strtolower($_SERVER[‘HTTPS’]==’on’))
$url=’https://’;
else
$url=’http://’;
if(isset($_SERVER[‘PHP_AUTH_USER’])){
$url.=$_SERVER[‘PHP_AUTH_USER’];
if(isset($_SERVER[‘PHP_AUTH_PW’]))
$url.=’:’.$_SERVER[‘PHP_AUTH_PW’];
$url.=’@’;
}
$url.=$_SERVER[‘HTTP_HOST’];
if($_SERVER[‘SERVER_PORT’]!=80 && $_SERVER[‘SERVER_PORT’]!=443)
$url.=’:’.$_SERVER[‘SERVER_PORT’];
$url.=$_SERVER[‘REQUEST_URI’];
return $url;
}

Justin Koivisto – sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
SEO Competition League: http://seo.koivi.com/

A(Answer):

In article <W5***************@news7.onvoy.net>, Justin Koivisto wrote:

OK… I’ve been watching this thread hoping that I’d snag a better
solution, but this is what I have been using:

Thanks for sharing your code, I was doing something like this myself by
now and just thought I’d ask here to foind a better solution.

If there is no other suggestion I am going to propose a feature request
for a $_SERVER[‘FULL_URI’] or similar 🙂

— Balu

LEAVE A COMMENT