Jump to content

Link using document root


kdreg

Recommended Posts

I've used document root for includes, but is it possible to use it for hyperlinks? I'm not able to get this to work and don't know if it's not possible or if my code is wrong (sorry, still not able to get the formatting buttons to format the code):

 

<a href='<?php $_SERVER["DOCUMENT_ROOT"] . "/forms/contact.php"; ?>'>Contact

                      Us</a>

 

Thanks

Link to comment
Share on other sites

Thank you! I see what I was doing wrong now.

 

Although it seems like that should have worked perfectly, I got a strange, unexpected result... it went too far and gave me my error page instead of the form, with this link:

 

/home/mydomain/public_html/forms/contact.php

 

Why is that? Something related to my server setup?

 

Thank you.

 

 

Link to comment
Share on other sites

Thank you. This is an interesting learning experience.

 

The new code appeared to be working at first, but for some reason it broke the links to css styles and logo images.

 

I'll work with it some more so I understand exactly what's happening with it.

 

I'm puzzled why document root works for the inc files but not how you showed it first for the link. Is there an easy explanation so that I can learn? I know when I've used document root before (over two years ago) that I used require once or require @ with it and it didn't bring up the public_html.

 

Thanks again, I appreciate your help and quick responses.

 

(I always thought google was my friend, but two times now when I've googled extensively for help (including last night) I've ended up with attempts to download trojans just by visiting web pages, even though they appeared to be safe sources. So I'm getting more and more afraid to search.)

 

Link to comment
Share on other sites

Hmmm, unfortunately I can't provide you with an experienced answer =/

 

/home/mydomain/public_html/forms/contact.php

 

That doesn't seem like a valid url. Isn't the "public_html" directory just the default directory for all you files? I think you are wanting you link to look like this:

 

domain.com/forms/contact.php

 

If you want to do that, just use this code:

<?php

echo '<a href="forms/contact.php">Contact Us</a>';

?>

 

You don't even have to type in your domain part as the link, as it will automatically fill that in for you.

Link to comment
Share on other sites

Yes, I think the public_html is the default directory, and I don't *think* the full path should have been visible.

 

I guess my original intent with using the document_root was in part to start brushing up on php since it's been over two years since I've really done any coding and can't remember very much; and, when I have files in different folders, then just having forms/contact.php won't work. I thought I'd try document root rather than putting in the full path since that always worked for my include files.

 

So, for now I just put in the full path, but this has been a good experience for me and is helping me to learn as I see other codes and I'm sure I'll have an occasion to use that again in a setting that will work.

 

Thank you very much!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.