[UPHPU] php equivalent of Request.ServerVariables

Sheri Bigelow design5279 at gmail.com
Fri Sep 9 12:35:39 MDT 2005


On 9/9/05, Wade Preston Shearer <lists at wadeshearer.com> wrote:
> 
> > Is there a way to get the current url using php or javascript? Like
> > Request.ServerVariables("URL") in asp?
> >
> > What I want to do is take a url like this:
> >
> > http://www.ashley.oviatt.whatever.com/
> >
> > and get the ashley and oviatt out of it to put on the current page.
> > I've seen code do this, but can't seem to find it anywhere.
> 
> Yes, in the $_SERVER global array:
> 
> $_SERVER['HTTP_HOST']


And, you could used something like this to remove the extra stuff from the 
url that you don't want. 

<?php
$url = $_SERVER['HTTP_HOST'];
// uncomment line below to test your url
// $url = "http://www.ashley.oviatt.whatever.com/";
$stufftoremove = array("http://", "www.", ".whatever", ".com/", ".com");
echo str_replace($stufftoremove, "", $url);
?>

Of course, you would have to know ahead of time that you want to remove "
whatever.com <http://whatever.com>" in this case. For "
http://www.ashley.oviatt.whatever.com/", the example above would return "
ashley.oviatt".



More information about the UPHPU mailing list