striping the string


Well i need prain transplantation, cause i forgot PHP by now… :oops:


This is what I do on one of my sites:

$ScriptName = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if ($_SERVER['HTTP_HOST'] == '' ){

Now this is obviously for a very specific domain (using the WWW) however you can do the same thing if It’s NOT the domain name you expect.

if ($_SERVER['HTTP_HOST'] != '' ){

It basically just re-directs them as you see appropriate. Might be a better way, but this one works just fine for me.

Good Luck.


aaaa, i went through your script like 8 times, and still mot ure what it does, at the end…

lat me give ore info on what i have:
i have like 40 domain names that are forwarded and masked to a spesific file called ‘id.php’ now in that file I need to identefy from what domain name was the requet forwarded and tha record that to a DB table for corresponding name

In orer for me to see thre original forwarded domain name i have to use $HTTP_REFERER or $REFERER the variables such as $_SERVER[‘HTTP_HOST’] will return the DNS name of the server there the file is hosted, and i dont need it…

$REFERER returns me the info in style: http://[domainname] where damain name can have any subdomains attached to it (that includes WWW etc.) so what I more need to do is to trim any subdomains or anything in between “http://” and “.” Ther is a specific function for that but i have bad memory and i cant find it in documentation


Do you mean substr?

I am having a hard time understanding what you mean.


I thought you wanted to have the input domain name modified to redirect to a specific domain name (in my example, I didn’t want to use I wanted it to go to )

Now I understand what you are wanting (I Think)

Anyway, I don’t know if there is a specific Function in PHP (Perhaps Bane might if he makes it back in here), but I have used the existing functions that will do the same thing.

// Put the global varible into a local variable

// gets rid of the HTTP://
$ref = substr($ref, 7);

// Gets rid of any lists of pages or scripts in the URL
$ref = substr($ref, 0, strpos($ref, '/'));

// Seperates the remaining into an array.
$ref1 = explode('.', $ref);

// Now pull the LAST 2 elements which are the domain name
$domainname = $ref1[(count($ref1)-2)].'.'.$ref1[(count($ref1)-1)];

// echo out the domain name to the screen
echo $domainname;


YEA, substr works for me!
Thanks ppl! :wink:

PS: Still there should be more simpler function that I used before, well some day ill fing it, hopefully