PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ive seen it done before, but Im not sure how to use it and could not find any examples searching with the keywords I was using. What I would like to know is how to use the document root code
How would I use the document root code to create a link so that no matter what page I put that link on its always pointing to the same resource. Sorry for such a simple question, I did try searching here and with google but was not coming up with much. I know you would have to escape the quotes and I think you would have to use the php echo function but Im not 100% and thought I would get some input on it.
Okay, I tried those out and I can see now that the HTTP_HOST is a better option as it echoes http://www.mydomain.com. Im assuming that its safe to use Document Root in includes, just not in the links, correct? So I would use HTTP_HOST when creating links? If that is so, then how do I format everything. I took a couple practice runs at it but I keep getting parse errors. I know I need to escape the quotes, but Im not sure what to do with the '<>' and '=' signs.
Anyway, not meaning to be a pest, just trying to learn. I pulled up that link as well and I tried a few of those in a test page to see what they output and Im going to have to play with some of those so I can get comfortable with their usage and purposes.
Hey SyntheticShield. You're not being a pest, we're all learning here and passing on knowledge.
Yes, 'DOCUMENT_ROOT' is a good option for includes. But for a browser link it would be useless because it shows public directory PLUS all the sub-directories as well and a browser wouldn't know what to do.
As for 'HTTP_HOST', post what you do have and I can point out why you are getting parse errors. For now, here is an example of using 'HTTP_HOST':
lukewilkins wrote:Hey SyntheticShield. You're not being a pest, we're all learning here and passing on knowledge.
Yes, 'DOCUMENT_ROOT' is a good option for includes. But for a browser link it would be useless because it shows public directory PLUS all the sub-directories as well and a browser wouldn't know what to do.
As for 'HTTP_HOST', post what you do have and I can point out why you are getting parse errors. For now, here is an example of using 'HTTP_HOST':
If you still have issues with it, let's see your code.
After seeing your version, I was making it WAY too complicated. For which I apologize. I was trying to figure it out on my own and I went off he deep end with the escape slashes. So thank you for that example, I very much appreciate it.
ghurtado wrote:The thing is, if you are linking within your own site, you don't even need the help of PHP. Start all your links with a slash, like this:
And they will work regardless of the location where you place the link.
I had not tried this and when it comes to simplistic solutions, I wish I had known about this a long time ago. I tried your version as well and it too worked like a champ. So now I have two ways to code links. Im having a great day I think with all that Ive learned here in the last few minutes.
Thank you both for taking the time to help out. Im trying to move away from pure HTML/XHTML and CSS and do things a bit more dynamic and I knew that was going to require I learn some php. I just wish I had started a long time ago. I was going to try and get my head around Ruby, but I think I'll start with php and work on that a while first.
I have spent some time looking over these two methods of creating the links. Would I be correct in stating that the HTTP_HOST method would be better for SEO?
While much of SEO is black magic and lore, myths and legends, I doubt any decent search engine pays much attention to whether you use the full server name in your internal links.