Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Problems Nested Includes

  • This topic is empty.
Viewing 12 posts - 16 through 27 (of 27 total)
  • Author
    Posts
  • #174709
    KKHAN
    Participant

    @chrisburton

    Yes i am saying it is correct from the output, but it is not applying. I have tried clicking page source. C:/xampp/htdocs/mysite/includes/css/style.css">
    i can’t clicked it but it says the address was not understood. I am now thinking it may have something to do with the way the xampp server is setup? As i currently access my files like this. http://localhost:63342/mysite/index.php

    Structure

    head.php

    overallHeader.php

    index.php

    dashboard.php

    #174710
    KKHAN
    Participant

    @chrisburton

    Yes i am saying it is correct from the output, but it is not applying. I have tried clicking page source. C:/xampp/htdocs/mysite/includes/css/style.css">
    i can’t clicked it but the address was not understood. i currently access my files like this. http://localhost/mysite/includes/css/style.css.

    Structure

    head.php

    overallHeader.php

    index.php

    dashboard.php

    #174715
    chrisburton
    Participant

    Is this for a client? Certainly not the most efficient way to go about it.

    I have to head out but I will say that I think you should start by combining overallHeader and head. What is the purpose of separating those?

    The problem seems to be using the global doc_root.

    The way you have your setup, it’s probably best to go with/mysite/includes/ and use../ depending on the level of your directories.

    #174716
    KKHAN
    Participant

    @chrisburton

    Nope this is not for a client. Its a fake site i have setup with the goal to learn PHP. I have used ../ in the past, however it works for dashboard.php file because it is nested in a folder, but when it comes to index.php which is not in a folder but in the root directory it fails.

    #174717
    chrisburton
    Participant

    but when it comes to index.php which is not in a folder but in the root directory it fails – @KKHAN

    I understand that. That’s the point I’m trying to make. You have to change ../ to reflect your level of directories. So for example with your index.php file, you would not use a slash nor ../.

    See this: http://hastebin.com/egaforofuy.vhdl

    #174728
    KKHAN
    Participant

    @chrisburton

    So do you recommend me removing document_root? I assumed it was always good to use this.

    So my index.php will look like this..

    <?php include (“includes/overall/overallHeader.php”);?>

    where as dashboard.php will look like this…

    <?php include (“../includes/overall/overallHeader.php”);?>

    regarding your hashbin, do you think its necessary for me to include the style sheet directly as your suggesting in every .php page, even tho im including it in the head.php which get included in the overallHeader.php.

    The purpose of me declaring it in the head, was that overallHeader will get used by every .php page so it would save duplication and should work everywhere regardless of nested .php files in folders.

    #174749
    KKHAN
    Participant

    Also i have in an image in my header.php

    When im in index.php, the src will be includes/images/myimage.css
    where as when im in profile/dashboard.php the src will be ../includes/images/myimage.css

    There must be a way ii can universally include images and style sheet no matter how deep i am in the folder structure if im including the overallHeader in every php file. As i can’t declare ../ and without at the same time.

    #174760
    chrisburton
    Participant

    The purpose of me declaring it in the head, was that overallHeader will get used by every .php page so it would save duplication and should work everywhere regardless of nested .php files in folders. @KKHAN

    Yes, sorry. I was completely exhausted – my fault. What you need to do is this:

    include('includes/css/style.css');
    

    If this does not work, zip MYSITE folder and upload it somewhere so I can download and take a closer look.

    #174778
    KKHAN
    Participant

    @chrisburton

    That’s alright.

    Where am i adding this piece of code?

    Bare in my mind i have the link rel in head.php

    Also i don’t wish to make this site public for everyone, is there some way we can do this more private?

    #174779
    chrisburton
    Participant

    @KKHAN

    Where am i adding this piece of code?

    head.php

    is there some way we can do this more private?

    chrisburton.me. You can find my email under my name. Make sure to zip the folder before attaching it to an email.

    #174780
    KKHAN
    Participant

    Ok i will try this and get back to you. Much appreciation for the help.

    Edit
    It just outputs the content of the style.css to the header, nothing gets applied though. Rightly so i think.

    #174782
    KKHAN
    Participant

    Solved.

    So there was actually a very simple solution.

    Just like with my includes. I added “$_SERVER[‘DOCUMENT_ROOT’]” to get the absolute path. I needed to do something similar with the href. Though for some reason it didint like $_SERVER[‘DOCUMENT_ROOT’] because it was pointing all the way back to the C: drive. I still needed to use an absolute path.

    In the end this worked, entering in a direct absolute path starting from the root with a leading /

    <link rel="stylesheet" type="text/css" href="/mysite/includes/css/style.css">

    Now, all my .php files which are held in subfolders properly render with the styling in place. This needs to be applied to all scripts/images also.

Viewing 12 posts - 16 through 27 (of 27 total)
  • The forum ‘Back End’ is closed to new topics and replies.