onlyican Posted September 24, 2006 Share Posted September 24, 2006 Hey guysI am tryna work on a scriptI need to know the domain and the page of the refererI am kinda doing this a long winded way, My Example[code]<?php$passed_by = $_SERVER['HTTP_REFERER'];if($passed_by){$parts_passed = explode("/", $passed_by);//Remembering a passed will have http://, as theres 2 / in http, I want third in array//Remembering an array starts on 0 in php, so it will be 2$domain_passed = $parts_passed[2]; //$num_parts = count($parts_passed);$last_in_parts = $num_parts - 1;$page_passed = "";for($i = 3; $i < $last_in_parts; $i ++){$page_passed .= $parts_passed[$i]."/";}$page_passed .= $parts_passed[$last_in_parts];}else{//Gonna do something here, might be a fault or direct hit}?>[/code]NOw with that code, I think it will workFor example, domain passed is http://localhost/mypage.php;then$domain_passed will be "localhost";and $page_passed will be mypage.phpExample beinghttp://www.example.com/folder/mypage.phpThen$domain_passed WILL be "www.example.com";$page_passed WIll be "folder/mypage.phpWhich is what I wantBUTis there a better way to do this Link to comment https://forums.phpfreaks.com/topic/21864-information-from-refered-url/ Share on other sites More sharing options...
alpine Posted September 24, 2006 Share Posted September 24, 2006 You might want to look at the parse_url() function:http://no.php.net/manual/en/function.parse-url.php Link to comment https://forums.phpfreaks.com/topic/21864-information-from-refered-url/#findComment-97653 Share on other sites More sharing options...
onlyican Posted September 24, 2006 Author Share Posted September 24, 2006 I keep doing thisMake nice functions when PHP has one already madeThanksDoes this grabwww.example.comor example.comor depending if www. is in use? Link to comment https://forums.phpfreaks.com/topic/21864-information-from-refered-url/#findComment-97656 Share on other sites More sharing options...
Daniel0 Posted September 24, 2006 Share Posted September 24, 2006 It do not need to have www. prepended. Link to comment https://forums.phpfreaks.com/topic/21864-information-from-refered-url/#findComment-97673 Share on other sites More sharing options...
onlyican Posted September 24, 2006 Author Share Posted September 24, 2006 [quote author=Daniel0 link=topic=109284.msg440392#msg440392 date=1159122631]It do not need to have www. prepended.[/quote]ok, thanks for that, it really really did not answer my questionRead::I am using $_SERVER['HTTP_REFERER'];if I parse that using url_parse();then I grab the host$parsed_url = parse_url($_SERVER['HTTP_SERVER'];$host = $parsed_url["host"];Now say that they came fromhttp://www.example.com/mypage.phpthen I come from http://example.com/mypage.php (NOTE: No www.)Are hosts the sameor is host on one example.com and the other www.example.com? Link to comment https://forums.phpfreaks.com/topic/21864-information-from-refered-url/#findComment-97710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.