Forum Moderators: coopster

Message Too Old, No Replies

Echo http host and make it a link

         

kkonline

7:17 am on Aug 23, 2007 (gmt 0)

10+ Year Member



i want to include a file
http://www.example.com/includes/connect.inc.php

using include "http://www.example.com/includes/connect.inc.php" in the processing page i get Access denied for user 'mysite'@'localhost' (using password: NO) But when i use
include "connect.inc.php"; then it authenticates.

i am including in the file located at http://www.example.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')

[edited by: dreamcatcher at 7:24 am (utc) on Aug. 23, 2007]
[edit reason] Use example.com, thanks. [/edit]

vincevincevince

10:03 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you read the file via link starting with http:// then you will see just what you would see visiting that page with your browser, which probably nothing.

Your options are either to make the connect.inc.php script insecure by removing the <?php and?> from around it (really bad idea) or to read it using a filesystem path.

Try:

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

kkonline

10:26 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Ya (vince) it works fine. Now next i want to make a link and echo and display image using http_host or document_root

<a href='$_SERVER[HTTP_HOST]/includes/connect.inc.php'> Link </a>

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

<img src="($_SERVER['HTTP_HOST'])/form/seccode.inc.php" width="71" height="21" align="absmiddle">

please let me know how to write the above echo image and link syntax

vincevincevince

12:10 pm on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why would you want to link directly to the connect file?

kkonline

12:14 pm on Aug 23, 2007 (gmt 0)

10+ Year Member



Actually i am storing the captcha image in includes folder and will link it through image and dispay in all the forms rather than keeping the ca[tcha image file with each form!

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

The code i used is correct BUT then it gives me image source as below

http://example.com/form/mysite.com/includes/seccode.inc.php

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

[edited by: eelixduppy at 12:21 pm (utc) on Aug. 23, 2007]
[edit reason] example.com [/edit]

vincevincevince

12:24 pm on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just add http:// before $_SERVER[HTTP_HOST]