php baseurl and <a href tag>

Discussion in 'PHP' started by KinetiX, Sep 7, 2008.

  1. #1
    ok so here is my issue.
    i have one original blog (WP) that i need to install it to 8 different domain names..everything easy so far, but i want to make it more easy
    the blog itself its easy to intsall but it has some links in header.php and footer.php that are like: <a href="www.site.com">.
    I don`t want for each blog to go inside these files and edit those urls to point to the different domain on wich it will be installed, i want it to take the domain from wich is accessed automatically..
    i guess something like this can be made but i don`t know how:
    <a href="<? $_SERVER['HTTP_HOST'] ?>
    or something like that..i`m asking cause i`m not too good at coding an dmight ruin everything lol
     
    KinetiX, Sep 7, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Use
    echo $_SERVER['HTTP_HOST'];
    or
    echo $_SERVER['SERVER_NAME'];
     
    mwasif, Sep 7, 2008 IP
  3. KinetiX

    KinetiX Member

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    KinetiX, Sep 7, 2008 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    echo $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
     
    mwasif, Sep 7, 2008 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    Dont forget to put http:// in the start e.g.
    <a href="http://<? echo $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; ?>
     
    mwasif, Sep 7, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Better yet: $_SERVER['REQUEST_URI'].

    Keep in mind that some of the $_SERVER vars are vulnerable to XSS attacks.
     
    nico_swd, Sep 7, 2008 IP
  7. KinetiX

    KinetiX Member

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    i just found out that WP has its own code for this:
    <?php bloginfo('name'); ?>
    then after i can just /folder/file.php normal whitout anything else
    thanks guys :)
     
    KinetiX, Sep 7, 2008 IP