SitePoint Sponsor

User Tag List

Page 3 of 4 FirstFirst 1234 LastLast
Results 51 to 75 of 89
  1. #51
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexp91k View Post
    Considering this is in "header.php", this will not work because "header.php" is included in different files of different subdirectory levels.

    Therefore, for sublevel 1, it may be able to find the stylesheets folder, but as soon as "header.php" is PHP-included into sublevel 2, it will not be able to find the directory.

    If I'm not understanding something or being unclear with the exact problem I'm having, please say so.
    Links that start with / always go to the document root, and it ignores which directory the user is in.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  2. #52
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    Links that start with / always go to the document root, and it ignores which directory the user is in.
    Right. I asked him how to solve the CSS problem. He said and you agree with using the / for document root, which I get.

    But the document root changes, meaning the / is not the same for both hosts, meaning that I must change the CSS paths (eg. absolute paths image files in home.css) each time I upload my files to the virtual host.

    Or so I think.

  3. #53
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexp91k View Post
    Right. I asked him how to solve the CSS problem. He said and you agree with using the / for document root, which I get.

    But the document root changes, meaning the / is not the same for both hosts, meaning that I must change the CSS paths (eg. absolute paths image files in home.css) each time I upload my files to the virtual host.

    Or so I think.
    The document root is always just simply /. There is no such thing as "/home/apache/..." or "C:/apache/htdocs" to the browser. Have you actually tried the code? Because I don't see why it wouldn't work if you did try it.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  4. #54
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    The document root is always just simply /. There is no such thing as "/home/apache/..." or "C:/apache/htdocs" to the browser. Have you actually tried the code? Because I don't see why it wouldn't work if you did try it.
    You know, I did a while back when I ran into this problem, but a lot of things have changed since then, so I think it would be wise to do that.

    If I have more problems, I'll surely be back.

  5. #55
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, here's an update:

    The following does not work:
    Code HTML4Strict:
           			<li><a href="screenprinting.php"><img src="/pages/images/product-screenprinting.png" /></a></li>

    The following does work:
    Code HTML4Strict:
           			<li><a href="screenprinting.php"><img src="/tenners/pages/images/product-screenprinting.png" /></a></li>

    Ok, so I can change all my absolute paths to have "tenners" in front of them. And now everything works in my local machine.

    Now when I place all these files into my virtual host, none of them work because it does not know what "tenners" is. The localhost root for "tenners" is "www" (because it is in a WAMP server), whereas in the virtual host, the root is "public_html".

    This is my dilemma, and I'm looking for a more efficient method as opposed to manually changing the absolute paths every time I upload my site to the Internet.

    So far, if hash comes back, I think his $root is the best solution (but I'm not seeming to get it right), and I haven't tried $_SERVER['DOCUMENT_ROOT'] yet, and I think I just proved that / doesn't work.

  6. #56
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The / DOES work, you are just using it on a wrong page.

    Are you trying to view the page in your browser using http://localhost/ or C:/.../../ or /home/.../../??! That is what it sounds like. You should only ever access the pages through a virtual host (like example.com, dev.example.com). Then using / in ever path will work perfectly, like it does for everybody else.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  7. #57
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    both $root and $_SERVER['DOCUMENT_ROOT'] won't help you with HTML. Better you understand it someday.

    you must have separate virtual servers for the each site on your localhost - it is the only solution

    if you don't have "tenners" on the virtual host - it shouldn't be on the localhost too

  8. #58
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    The / DOES work, you are just using it on a wrong page.

    Are you trying to view the page in your browser using http://localhost/ or C:/.../../ or /home/.../../??! That is what it sounds like. You should only ever access the pages through a virtual host (like example.com, dev.example.com). Then using / in ever path will work perfectly, like it does for everybody else.
    Yes, I am accessing the pages through http://localhost/tenners/pages/index.php.

    Should I not be?

    And @Shrapnel_N5, could you stop criticizing me about HTML? If you think me not knowing about / (site root, which I know anyway) represents my whole knowledge of XHTML, you are very ignorant. Could you discontinue posting?

  9. #59
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexp91k View Post
    Yes, I am accessing the pages through http://localhost/tenners/pages/index.php.

    Should I not be?
    No. You should use a virtual host for local development.

    Edit: localhost is a virtual host, but not the kind I mean. I mean like dev.tenners.com (if your actual public site is tenners.com)
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  10. #60
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry.
    I am not the source of your problem.
    It is not me, who think you not knowing about /
    It was you, who mentioned $_SERVER['DOCUMENT_ROOT'] in the HTML context and want to add it tho the virtual /
    I but point to this error.
    Should I not be?
    yes.
    it must be http://tenners.local/pages/index.php

  11. #61
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    No. You should use a virtual host for local development.
    Ah alright. This must be where my error is. I had always thought you can work on localhost to locally test.

    So instead, I'm supposed to do all my changes, then upload them each time to the virtual server to see if they work?

  12. #62
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, it's unnecessary.
    many developers use their PC's to develop and testing.

  13. #63
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexp91k View Post
    Ah alright. This must be where my error is. I had always thought you can work on localhost to locally test.

    So instead, I'm supposed to do all my changes, then upload them each time to the virtual server to see if they work?
    In your computer's Apache settings, find a file called httpd-vhosts.conf, then add something like:


    <VirtualHost dev.tenners.com>
    DocumentRoot "D:/xampp/htdocs/tenners"
    </VirtualHost>


    Restart Apache.

    Then in your Windows "hosts" file set dev.tenners.com to point to 127.0.0.1.

    Now you can access dev.tenners.com, which runs on the computer right beside you, and you can edit the files on your computer and don't need to do any uploading.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  14. #64
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    In your computer's Apache settings, find a file called httpd-vhosts.conf, then add something like:


    <VirtualHost dev.tenners.com>
    DocumentRoot "D:/xampp/htdocs/tenners"
    </VirtualHost>


    Restart Apache.

    Then in your Windows "hosts" file set dev.tenners.com to point to 127.0.0.1.

    Now you can access dev.tenners.com, which runs on the computer right beside you, and you can edit the files on your computer and don't need to do any uploading.
    I think I'm slowly getting it.. So to confirm:

    /tenners/pages/index.php doesn't work on the virtual host (hostmonster), and /pages/index.php, and after a bit of testing, I found out that /home1/username/public_html/tenners/index.php works.

    This means that in my coding, I make all the absolute path names using "/home1/username/public_html/tenners/index.php". Then in the Apache config, I simply point that absolute path name into a localized URL like dev.tenners.com?

  15. #65
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexp91k View Post
    I think I'm slowly getting it.. So to confirm:

    /tenners/pages/index.php doesn't work on the virtual host (hostmonster), and /pages/index.php, and after a bit of testing, I found out that /home1/username/public_html/tenners/index.php works.

    This means that in my coding, I make all the absolute path names using "/home1/username/public_html/tenners/index.php". Then in the Apache config, I simply point that absolute path name into a localized URL like dev.tenners.com?
    Hostmonster is a web host not a virtual host. Very different things. A VHost is just something that exists in a specific Apache config. A web host is a company.

    In HTML, it does not need to know about /home1/.../ (it will break if you tell it that). Just tell it /.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  16. #66
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    Hostmonster is a web host not a virtual host. Very different things. A VHost is just something that exists in a specific Apache config. A web host is a company.

    In HTML, it does not need to know about /home1/.../ (it will break if you tell it that). Just tell it /.
    Sorry for the wrong jargon, I guess I meant webhost the whole time. Anyway, so in the example below, I did just /pages/index.php and it spit back the error, also shown.


  17. #67
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do one thing at a time.
    If you going to set up CSS file for the HTML - set up CSS file for the HTML.
    in this case use the / thing

    If you going to unclude a file - welcome back to the $root and $_SERVER['DOCUMENT_ROOT'] world

    Do not dash between your tasks.

  18. #68
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    Do one thing at a time.
    If you going to set up CSS file for the HTML - set up CSS file for the HTML.
    in this case use the / thing

    If you going to unclude a file - welcome back to the $root and $_SERVER['DOCUMENT_ROOT'] world

    Do not dash between your tasks.
    So the CSS will automatically know which root it's starting at? If just type /, it will know to start at the folder of my website, not public_html?

  19. #69
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexp91k View Post
    So the CSS will automatically know which root it's starting at? If just type /, it will know to start at the folder of my website, not public_html?
    public_html probably is the folder of your website. If you start a link or css location with /, it will point to your *public* document root, which for most people is public_html.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  20. #70
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps think of it like this
    http://site.com/page
    In your code you don't need site.com, you know you are at site.com, so you just start from /
    so in your html, /page means http://site.com/page on your live host and http://site.local/page on your local virtual server. If you don't have a virtual site on local then it means http://localhost/page which is wrong as you want http://localhost/tenner/page

    Hope that makes sense.

  21. #71
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the trouble is me finding the root file.

    In the example (picture) above, as shown in the PHP file, I tried "/pages/test.php" which clearly did not work.

    However, when I did the following (PHP included), it did work:
    "/home1/username/public_html/website/pages/test.php"

    Should it be working like this? Is the root file really the parent of "home1"?

  22. #72
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    To make things more clear, you're actually attacking two similar problems at the same time here, and you're constantly confusing the two.

    Problem 1. Where does the application live?
    In this case you need to know which php files to include, and where they reside. As pointed out several posts ago dirname(__FILE__) is your friend here.
    In this case you are using the file system of the server, which does not restrict you in any way, so you can do inludes like /home1/etc

    Problem 2. Where do my resource (images, etc) live?
    This is another problem, and the key here is that if you have your website on a path like /home/scallio/public_html, only files in the public_html directory and it's subdirectories can be seen by the web browser.
    So, what the web server sees as /home/scallio/public_html/, the webserver sees as /, and what the web server sees as /home/scallio/public_html/images the web server sees as /images, and so on and so forth.

  23. #73
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    if you don't have "tenners" on the virtual host - it shouldn't be on the localhost too
    Off Topic:


    Interesting you should say this, since this is exactly what I proposed in post #5 of this thread. A proposal you subsequently bashed in post #7 of this tread ...

  24. #74
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    To make things more clear, you're actually attacking two similar problems at the same time here, and you're constantly confusing the two.

    Problem 1. Where does the application live?
    In this case you need to know which php files to include, and where they reside. As pointed out several posts ago dirname(__FILE__) is your friend here.
    In this case you are using the file system of the server, which does not restrict you in any way, so you can do inludes like /home1/etc

    Problem 2. Where do my resource (images, etc) live?
    This is another problem, and the key here is that if you have your website on a path like /home/scallio/public_html, only files in the public_html directory and it's subdirectories can be seen by the web browser.
    So, what the web server sees as /home/scallio/public_html/, the webserver sees as /, and what the web server sees as /home/scallio/public_html/images the web server sees as /images, and so on and so forth.
    This is a very clear explanation and I appreciate this a lot; since I am just thick-headed, I will continue to ask questions until I understand this concept fully.

    So for problem 1, I should go back to the previous methods, such as the while-loop to find the root.txt and create a $root variable (in which case I still have a problem as referenced on post #47).

    For problem 2, you're saying that there's an inherent problem between what the web browser sees and what the webserver sees? If I am right in what you are saying, what is the solution for this?

  25. #75
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by alexp91k View Post
    So for problem 1, I should go back to the previous methods, such as the while-loop to find the root.txt and create a $root variable (in which case I still have a problem as referenced on post #47).
    You could use this approach yes, but beware that if there is no root.txt anywhere you'll get an infinite loop. Using dirname(__FILE__) is much nicer in my opinion.


    Quote Originally Posted by alexp91k View Post
    For problem 2, you're saying that there's an inherent problem between what the web browser sees and what the webserver sees? If I am right in what you are saying, what is the solution for this?
    I wouldn't classify it as a problem, but a bliss. What if I could access the /etc/passwd of a server through a browser?? (if you're not familiar with linux, that file holds all information on users/password etc)

    As for a solution, the way I use is:
    If a php file is not in a subdirectory on the live webserver, then it should also not be in a subdirectory on my local web server.

    So, if I'm creating examle.com and have a file example.com/index.php, on my own pc I shouldn't have localhost/example/index.php, since that doesn't match.
    I should have instead something like example.local/index.php
    That way I also have example.com/images and example.local/images, and I can put /images in my HTML/CSS on both servers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •