phpQuestioner Posted May 10, 2007 Share Posted May 10, 2007 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? Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/ Share on other sites More sharing options...
neel_basu Posted May 10, 2007 Share Posted May 10, 2007 $url_r = explode('.'.$url); print_r($url_r); I hope it will work Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/#findComment-249542 Share on other sites More sharing options...
phpQuestioner Posted May 10, 2007 Author Share Posted May 10, 2007 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); ?> Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/#findComment-249543 Share on other sites More sharing options...
neel_basu Posted May 10, 2007 Share Posted May 10, 2007 $url = 'www.sub.domain.com'; $url_r = explode('.'.$url); print_r($url_r); Try this. Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/#findComment-249546 Share on other sites More sharing options...
neel_basu Posted May 10, 2007 Share Posted May 10, 2007 OOPS there was a mistake <?php $url = 'www.sub.domain.com'; $url_r = explode('.',$url);// print_r($url_r); ?> Use this it would work Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/#findComment-249550 Share on other sites More sharing options...
jitesh Posted May 10, 2007 Share Posted May 10, 2007 OOPS there was a mistake <?php $url = 'www.sub.domain.com'; $url_r = explode('.',$url);// print_r($url_r); ?> Use this it would work Yes echo $url_r[1].".".$url_r[2]; Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/#findComment-249553 Share on other sites More sharing options...
phpQuestioner Posted May 10, 2007 Author Share Posted May 10, 2007 That Will Work - Thanks For The Help Link to comment https://forums.phpfreaks.com/topic/50759-solved-using-parse_url-to-cut-all-of-http_referer-out-except-domaincom/#findComment-249560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.