Variable, Get Url???

Discussion in 'PHP' started by dkin69, Apr 26, 2007.

  1. #1
    Ok this is my problem.

    I have a script I am using as an include in many sites. It pulls info from a database and displays ads. Now every site that this is displayed on has an ad in the database and I dont want anyones ads showing on their own site.

    I wrote this.

    ##$current = $_SERVER["HTTP_HOST"];
    $current = $_SERVER['PHP_SELF'];

    $lin = mysql_query("SELECT * FROM link order by id asc", $link) or die ("query 1: " . mysql_error());
    echo '<li><h2>LinkWork</h2>'
    . '<ul>';
    while ($li = mysql_fetch_array($lin)) {
    if ($current == $li['base'])
    {
    echo '';
    }
    else
    {
    echo '<li><a href="'.$li['web_url'].'" alt="'.$li['alt_tag'].'">'.$li['display'].'</a></li>';

    }
    }

    The column base, is the base of a url eg. digitalpoint.com

    So that is what I need to find, a php variable that gives me the current pages web address, but only up to the end of the com or org.
     
    dkin69, Apr 26, 2007 IP
  2. weppos

    weppos Well-Known Member

    Messages:
    99
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    125
    #2
    Use

    parse_url()
    PHP:
    function. :)
     
    weppos, Apr 26, 2007 IP
  3. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I assume from the comment that HTTP_HOST isn't enough? There's no server variable as such containing a full URL but you can put it together yourself.
    $currentURL = 'http'.(empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['HTTP_HOST'];
    PHP:
    If you want to go further than the hostname, you'd just need to add the REQUEST_URI
     
    rodney88, Apr 26, 2007 IP
  4. ttnhatan

    ttnhatan Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Maybe add more dir url

    Above code . dirname($_SERVER['PHP_SELF']) 
    PHP:
     
    ttnhatan, Apr 26, 2007 IP