SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot revivalx's Avatar
    Join Date
    Dec 2009
    Location
    Kuala Lumpur,Malaysia
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SERVER['HTTP_HOST'] in href?

    How to put $_SERVER['HTTP_HOST'] in href tag?


    Web advertising solution

    Business is not about money, it is about trust..

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,033
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    You mean <a href="<?php echo $_SERVER['HTTP_HOST']; ?>"> ?
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Zealot revivalx's Avatar
    Join Date
    Dec 2009
    Location
    Kuala Lumpur,Malaysia
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i mean like that, that method is really works? for sure?

    can I do like this
    <a href="<?php echo $_SERVER['HTTP_HOST'] . "/admin.php" ; ?>">Admin</a>


    Web advertising solution

    Business is not about money, it is about trust..

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,033
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    I'm guessing you want a link to an absolute URL, am I right?

    In that case it would be

    <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/admin.php">Admin</a>

    That is, you need to prepend "http://", and there's no need to let PHP handle "http://" and "/admin.php" as well
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Also remember that the value in $_SERVER['HTTP_HOST'] (if there is one!) is user input, just like any $_GET/$_POST values. You'll need to properly sanitize/validate/escape its value.
    Salathe
    Software Developer and PHP Manual Author.

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Not to mention that if you're trying to make a generic package, HTTP_HOST will contain the domain name, but not any subfolders the script may be hiding in.

    EG: I install your script into http://www.example.com/testscript/admin.php
    <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/admin.php">Admin</a> is going to point to http://www.example.com/admin.php, not the URL expected.

  7. #7
    SitePoint Zealot revivalx's Avatar
    Join Date
    Dec 2009
    Location
    Kuala Lumpur,Malaysia
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, it works


    Web advertising solution

    Business is not about money, it is about trust..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •