Jump to content

[SOLVED] Using Parse_URL To Cut All of HTTP_REFERER Out Except "domain.com"


phpQuestioner

Recommended Posts

Ok I learn a couple of days ago how to use parse_url to remove a certin part of HTTP_REFERER.

 

Like So:

 

<?php

  $fowarded = $_SERVER['HTTP_REFERER'];
  $url = "$fowarded";
  $parts = parse_url($url);

// use as needed
// print "http://";

  print $parts["host"];

?> 

 

 

But now I want to be able to remove any sub-domain or sub-directory before actual domain.

 

Example

 

HTTP_REFERER Address: sub1.domain.com

 

What I Want To Display: domain.com (I want to strip off the "sub1" part).

 

 

 

Any one know how I can do this? Do I still use parse_url and if so, how?

I tried this; but I did not get anything. So what am I doing wrong?

 

<?php

  $fowarded = $_SERVER['HTTP_REFERER'];

  $url = "$fowarded";

  $url_r = explode('.'.$url);

  print_r($url_r);

?>

 

And This.........

 

<?php

  $fowarded = $_SERVER['HTTP_REFERER'];
  $url = "$fowarded";
  $parts = parse_url($url);

  $url_r = $parts["host"];

  $url_r = explode('.'.$url);
  print_r($url_r);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.