This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > June 2004 > Plugging in "Constant" Links





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Plugging in "Constant" Links
David B

2004-06-09, 11:14 pm

ZendStudio suggested I use "constant" include links as a security
measure, so my include links now look like this:

<?php include ($_SERVER['DOCUMENT_ROOT']."/includes/footer.php"); ?>

But I haven't figured out how to plug that into non-include links. For
example, suppose I have this in my head section:

<?php
$path = '../../../';
$_SERVER['DOCUMENT_ROOT'];
?>

and this in the body:

<a href="<?php echo "$path" ?>reference/hot/index.php">Hot References</a>
<?php include ($_SERVER['DOCUMENT_ROOT']."/includes/footer.php"); ?>

First of all, I should be able to delete $path = '../../../'; from the
head section and plug $_SERVER['DOCUMENT_ROOT']; into the "Hot
References link, right? In other words, my body would look something
like this:

<a href="<?php ($_SERVER['DOCUMENT_ROOT']
?>.'reference/hot/index.php'">Hot References</a>
<?php include ($_SERVER['DOCUMENT_ROOT']."/includes/footer.php"); ?>

Right?

But the first line...

<a href="<?php ($_SERVER['DOCUMENT_ROOT']
?>.'reference/hot/index.php'">Hot References</a>

....doesn't work. I've tried serveral variations, using various
combinations of quotes, single quotes, etc.

My assumption is that, when I'm all finished, every reference to $path =
'../../../'; on my site will be replaced with some variation of
$_SERVER['DOCUMENT_ROOT'];, which will apparently make my site more secure.

Any tip?
Gary White

2004-06-09, 11:14 pm

"David B" <david_blomstromDELETETHIS@yahoo.com> wrote in message
news:ca883n$shu$1@forums.macromedia.com...
>
> But the first line...
>
> <a href="<?php ($_SERVER['DOCUMENT_ROOT']
> ?>.'reference/hot/index.php'">Hot References</a>
>
> ...doesn't work. I've tried serveral variations, using various
> combinations of quotes, single quotes, etc.



<a href="<?php echo
$_SERVER['DOCUMENT_ROOT']."/reference/hot/index.php"?>">Hot References</a>

Gary


David B

2004-06-09, 11:14 pm

Gary White wrote:

> "David B" <david_blomstromDELETETHIS@yahoo.com> wrote in message
> news:ca883n$shu$1@forums.macromedia.com...
>
>
>
>
> <a href="<?php echo
> $_SERVER['DOCUMENT_ROOT']."/reference/hot/index.php"?>">Hot References</a>


Sheez, I don't know how I forgot to include echo! Thanks.

Not it works - almost. A link that used to look something like this in
the source code...

<a href="../../world/index.php">Hot References</a>

now looks like this, thanks to my new virtual host set up:

<a href="C:/sites/mysite/world/index.php">Hot References</a>

When I preview it, I get this error message:

"C is not a registered protocol."

Do you have any idea what that's all about? $_SERVER['DOCUMENT_ROOT']
works for my includes, but not for my links.
Gary White

2004-06-10, 4:14 am

"David B" <david_blomstromDELETETHIS@yahoo.com> wrote in message
news:ca8ab5$1j0$1@forums.macromedia.com...
References</a>[color=darkred]
>
> Sheez, I don't know how I forgot to include echo! Thanks.
>
> Not it works - almost. A link that used to look something like this in
> the source code...
>
> <a href="../../world/index.php">Hot References</a>
>
> now looks like this, thanks to my new virtual host set up:
>
> <a href="C:/sites/mysite/world/index.php">Hot References</a>



Crap! I was so wrapped up in getting the path right that I completely
ignored the fact that it was in an HTML link. Links don't use the machine's
file system. They start out at the document root. Change it to this:

<a href="<?php echo "/reference/hot/index.php"?>">Hot References</a>

Gary


David B

2004-06-10, 4:14 am

Gary White wrote:

> "David B" <david_blomstromDELETETHIS@yahoo.com> wrote in message
> news:ca8ab5$1j0$1@forums.macromedia.com...
>
>
> References</a>
>
>
>
>
> Crap! I was so wrapped up in getting the path right that I completely
> ignored the fact that it was in an HTML link. Links don't use the machine's
> file system. They start out at the document root. Change it to this:
>
> <a href="<?php echo "/reference/hot/index.php"?>">Hot References</a>
>
> Gary


BINGO! I should have remembered that, too; I experimented with that kind
of link one time but had to abandon it; I think because I didn't have
virtual hosting set up yet.

Anyway, thanks for all the help. It's so nice to finally be finished
with constant/absolute links. Whew!
Gary White

2004-06-10, 4:14 am

"David B" <david_blomstromDELETETHIS@yahoo.com> wrote in message
news:ca8i1h$8t4$1@forums.macromedia.com...
>
> BINGO! I should have remembered that, too; I experimented with that kind
> of link one time but had to abandon it; I think because I didn't have
> virtual hosting set up yet.
>
> Anyway, thanks for all the help. It's so nice to finally be finished
> with constant/absolute links. Whew!



You're welcome. Glad you got it working.

Gary


Michael Fesser

2004-06-10, 12:14 pm

.oO(David B)

>Do you have any idea what that's all about? $_SERVER['DOCUMENT_ROOT']
>works for my includes, but not for my links.


DOCUMENT_ROOT is the physical location (that means in the server's file
system) of what appears as the "logical" site root ('/') in the browser.

All requests from the browser via HTTP use the logical structure, while
PHP accesses the files directly through the server's file system. You
can use it to include files, but not for HTTP-links.

HTH
Micha
Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews