Including a file with the domain

Discussion in 'PHP' started by webboy, Jul 22, 2007.

  1. #1
    Hi all this must be easy

    i have 5 webpage all on different domains

    i need to a insert some text from a different domain and display the domain name the at page is on and on not the remote site

    here is the code

    on each site = the include http://www.mydoamin.co.uk/text.php

    the text

    <?php
    $hostname = $_SERVER['HTTP_HOST'];
    $hostname = str_replace('www.','',$hostname);
    $hostname = str_replace('.co.uk','',$hostname);
    ?>

    ... echo hostname

    but this displays the host name of where the included file is located but I would like to display the domain name where the file has been called from
     
    webboy, Jul 22, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Probably a redirect is what you need to do. There is no way to change what the user sees the domain name as.

    Try:
    
    
    $hostname = $_SERVER['HTTP_HOST'];
    $hostname = str_replace('www.','',$hostname);
    $hostname = str_replace('.co.uk','',$hostname);
    
    header("Location: http://".$hostname."");
    
    
    PHP:
     
    jestep, Jul 22, 2007 IP
  3. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Instead of including the file, use a fopen to retrieve it and then echo it into your page. That way, you can pass the current HOST to the remote script as a url parameter and retrieve it within that script using $_GET.
     
    ecentricNick, Jul 23, 2007 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    
    <?php
      $sites = explode("/",$_SERVER['HTTP_REFERER']);
      $site = $sites[2];
    ?>
    
    PHP:
    This has worked for me most of the time.
     
    exodus, Jul 23, 2007 IP