Jump to content

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


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);

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.