SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Echo http_host and make it a link

    i want to include a file which is in the root directory as shown
    http://mysite.com/includes/connect.inc.php

    using include "http://mysite.com/includes/connect.inc.php" in the processing doesnot authenticate and connect to db but when i use
    include "connect.inc.php"; then it authenticates.

    i am including in the file located at http://mysite.com/form/test/post.php

    Any solution?

    I thought if i could use http_host instead of writing the url then it would be ok.

    Please let me know the correct syntax/method of using the below 3

    <? echo ($_SERVER['HTTP_HOST'])/form/index.php ?>

    <a href="{$_SERVER['HTTP_HOST']}/form/test/index.php>go here</a><br />

    include('$_SERVER['HTTP_HOST']includes/connect.inc.php')

  2. #2
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when you include a file you can't do it by using the URL, but you have to specify the path in your local file system. You can get the base directory of your domain by using $_SERVER['DOCUMENT_ROOT'].
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by kleineme View Post
    when you include a file you can't do it by using the URL, but you have to specify the path in your local file system. You can get the base directory of your domain by using $_SERVER['DOCUMENT_ROOT'].
    Ok so for the below 3 can you tell me the correct syntax

    <? echo ($_SERVER['HTTP_HOST'])/form/index.php ?>

    <a href="{$_SERVER['HTTP_HOST']}/form/test/index.php>go here</a><br />

    include('$_SERVER['DOCUMENT_ROOT']includes/connect.inc.php')

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <? echo $_SERVER['HTTP_HOST'] . '/form/index.php'?>
    Code:
    <a href="<? echo $_SERVER['HTTP_HOST']; ?>/form/test/index.php">go here ASAP</a><br />
    PHP Code:
    include($_SERVER['DOCUMENT_ROOT']. '/includes/connect.inc.php'

  5. #5
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    thanks for all the syntax another thing it with image
    Code:
    <img src="($_SERVER['HTTP_HOST'])/form/seccode.inc.php" width="71" height="21" align="absmiddle">
    please let me know how to write the above image code using http_host
    Last edited by krishnakhanna; Aug 23, 2007 at 04:29.

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for the PHP parser to look for code, the code must be enclosed in the special PHP tags <? and ?>. your code is almost right, try this:

    Code:
    <img src="<? echo $_SERVER['HTTP_HOST']; ?>/form/seccode.inc.php" width="71" height="21" align="absmiddle">

  7. #7
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Quote Originally Posted by XtrEM3 View Post
    for the PHP parser to look for code, the code must be enclosed in the special PHP tags <? and ?>. your code is almost right, try this:

    Code:
    <img src="<? echo $_SERVER['HTTP_HOST']; ?>/includes/seccode.inc.php" width="71" height="21" align="absmiddle">
    The code you posted is correct BUT then it gives me image source as below

    http://mysite.com/form/mysite.com/in...eccode.inc.php

    It should be
    http://mysite.com/includes/seccode.inc.php

  8. #8
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    it needs to be:
    PHP Code:
    <img src="http://<? echo $_SERVER['HTTP_HOST']; ?>/includes/seccode.inc.php" width="71" height="21" align="absmiddle" />
    But to be more efficient, why not just use:
    PHP Code:
    <img src="/includes/seccode.inc.php" width="71" height="21" align="absmiddle" /> 
    ?
    putting a slash at the front of the src means it is from the root directory.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #9
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    it needs to be:
    PHP Code:
    <img src="http://<? echo $_SERVER['HTTP_HOST']; ?>/includes/seccode.inc.php" width="71" height="21" align="absmiddle" />
    But to be more efficient, why not just use:
    PHP Code:
    <img src="/includes/seccode.inc.php" width="71" height="21" align="absmiddle" /> 
    ?
    putting a slash at the front of the src means it is from the root directory.
    The second solution is much better and efiicieant as you say. Thanks

  10. #10
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    it needs to be:
    PHP Code:
    <img src="http://<? echo $_SERVER['HTTP_HOST']; ?>/includes/seccode.inc.php" width="71" height="21" align="absmiddle" />
    But to be more efficient, why not just use:
    PHP Code:
    <img src="/includes/seccode.inc.php" width="71" height="21" align="absmiddle" /> 
    ?
    putting a slash at the front of the src means it is from the root directory.
    The second solution is much better and efficient as you say. Thanks

  11. #11
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    thanks a tonne


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
  •