kdreg Posted June 20, 2007 Share Posted June 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/ Share on other sites More sharing options...
pocobueno1388 Posted June 20, 2007 Share Posted June 20, 2007 Do it like this: <?php echo '<a href="'.$_SERVER["DOCUMENT_ROOT"].'/forms/contact.php">Contact Us</a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/#findComment-278103 Share on other sites More sharing options...
kdreg Posted June 20, 2007 Author Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/#findComment-278111 Share on other sites More sharing options...
pocobueno1388 Posted June 20, 2007 Share Posted June 20, 2007 I think you are looking for a different variable.... Try this and see if it is what you want: <?php echo '<a href="'.$_SERVER['PHP_SELF'].'/forms/contact.php">Contact Us</a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/#findComment-278113 Share on other sites More sharing options...
kdreg Posted June 20, 2007 Author Share Posted June 20, 2007 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.) Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/#findComment-278137 Share on other sites More sharing options...
pocobueno1388 Posted June 20, 2007 Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/#findComment-278141 Share on other sites More sharing options...
kdreg Posted June 20, 2007 Author Share Posted June 20, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/56299-link-using-document-root/#findComment-278154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.