o3xa Posted April 21, 2012 Share Posted April 21, 2012 how to get the domain name of a website which includes my includes file. The code would need to be put within my includes file so when any site includes it the file will get the sites domain. to $currentDomain i have tried using: echo file_get_contents() instead of includes but i get the same issue I get back the includes domain. then code i have tried (in the includes file): $curdomain1= $_SERVER['HTTP_HOST']; $pageUR1 = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); $curdomain2 = str_replace("www.", "", $pageUR1); echo "<br> 1# Current Domain: ".$curdomain1; echo "<br> 2# Current Domain: ".$curdomain2; Quote Link to comment https://forums.phpfreaks.com/topic/261365-get-the-domain-name-of-a-website-which-includes-my-includes-file/ Share on other sites More sharing options...
kicken Posted April 21, 2012 Share Posted April 21, 2012 How are you including this file? If you include it via a file path, eg: include('/path/to/include.php'); Then the domain should just be in $_SERVER['HTTP_HOST']. If your including it as a URL though, say include('http://www.yoursite.com/include.php'); Then you have to pass the domain as a parameter in the query string in order to get it in the include. Quote Link to comment https://forums.phpfreaks.com/topic/261365-get-the-domain-name-of-a-website-which-includes-my-includes-file/#findComment-1339292 Share on other sites More sharing options...
o3xa Posted April 21, 2012 Author Share Posted April 21, 2012 How are you including this file? If you include it via a file path, eg: include('/path/to/include.php'); Then the domain should just be in $_SERVER['HTTP_HOST']. If your including it as a URL though, say include('http://www.yoursite.com/include.php'); Then you have to pass the domain as a parameter in the query string in order to get it in the include. hi there thanks for the response. i have included it like this: <?php include("http://o3xa-seo.info/bata-links.php?amount=10"); ?> the includes works but as i put the: $currentDomain = $_SERVER['HTTP_HOST']; in the included php file i get the domain of the included file 'o3xa-seo.info' not the domain of the website which has the include code: http://www.rizzlekicks.org/ look at the footer. for the result. is there a way around this, maybe a bit of javascript? any help welcome thanks Quote Link to comment https://forums.phpfreaks.com/topic/261365-get-the-domain-name-of-a-website-which-includes-my-includes-file/#findComment-1339302 Share on other sites More sharing options...
kicken Posted April 21, 2012 Share Posted April 21, 2012 Pass the domain as a parameter in the URL. include('http://o3xa-seo.info/bata-links.php?amount=10&domain='.urlencode($_SERVER['HTTP_HOST'])); Quote Link to comment https://forums.phpfreaks.com/topic/261365-get-the-domain-name-of-a-website-which-includes-my-includes-file/#findComment-1339303 Share on other sites More sharing options...
o3xa Posted April 21, 2012 Author Share Posted April 21, 2012 Pass the domain as a parameter in the URL. include('http://o3xa-seo.info/bata-links.php?amount=10&domain='.urlencode($_SERVER['HTTP_HOST'])); thanks, still learning Quote Link to comment https://forums.phpfreaks.com/topic/261365-get-the-domain-name-of-a-website-which-includes-my-includes-file/#findComment-1339305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.