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 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #174671
    KKHAN
    Participant

    Hi i am having problem with includes. Specifically when including my head which contains the link to the style.css. Although the style.css applies to the index page. It does not for my other .php files which are nested in a folder.

    Structure

    -ROOT
    -INCLUDES
    -OVERALL
    overallHeader.php
    overallFooter.php
    -STYLE
    style.css
    head.php
    footer.php
    header.php
    index.php
    -PROFILE
    dashboard.php

    My stylesheet is working for index.php but not dashboard.php. In dashboard.php, just like index.php i am including the overallHeader.php which includes the header.php and the head.php (which contains the link rel to style.css).

    However, in index.php for the style to work i am including the overallHeader like this…
    <?php include ('includes/overall/overallHeader.php'); ?>

    Where as in dashboard.php i am including the overallHeader like this.
    <?php include ($_SERVER['DOCUMENT_ROOT']."/includes/overall/overallHeader.php");?>
    By using the the document root, it works because i can see the html output just the style is not applied.

    In my head.php i am using
    <link rel="stylesheet" type="text/css" href="includes/css/style.css">

    Is there something i need to change to href, i have tried prefix echoing the document_root, but then the style.css does not work for index.php.

    If i check the logs in dashboard.php it shows this.

    “NetworkError: 404 Not Found – http://localhost:63342/MYSITE/profile/includes/css/style.css&#8221; which is wrong.

    #174674
    chrisburton
    Participant

    Try something like this:

    <link rel="stylesheet" type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"].'../includes/css/style.css'; ?>">
    
    #174678
    KKHAN
    Participant

    Using your method the style does not show up on both dashboard and index.php

    But whats weird is there is no console error for style sheet, there is for the script.js but i can fix that later.

    Seems odd. Firebug css is still not showing though.

    #174679
    chrisburton
    Participant

    @KKHAN Fixed the above code. I forgot the echo.

    Note: you may have to play with ../includes/ depending how deep the directories go.

    For example, dashboard.php would require ../includes where as index.php would require includes/

    #174680
    KKHAN
    Participant

    This did not work for this reason.

    C:/xampp/htdocs/MYSITE../includes/css/style.css

    This is what your statements echos out. ive removed the “..” still doesen’t work.

    MY includes all have $_SERVER[‘DOCUMENT_ROOT’]. They bring back the html so i assume they are all working. Just the css won’t apply.

    #174681
    chrisburton
    Participant

    @KKHAN

    If it is outputting this:

    C:/xampp/htdocs/MYSITE../includes/css/style.css
    

    Then it should look like this: http://hastebin.com/wuduzoxuwe.xml
    `

    I had to post it on hastebin because CSS-Tricks was throwing a firewall error.

    #174682
    KKHAN
    Participant

    @chrisburton

    That code would show this, which it does.

    #174683
    KKHAN
    Participant

    @chrisburton

    Can’t post what i want because of firewall

    #174684
    chrisburton
    Participant

    @KKHAN use http://pastebin.com.

    Paste what you’re trying to show me, click submit and post the URL in the address bar.

    #174685
    Senff
    Participant

    How about this?

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

    Notice the slash before “includes”.

    #174686
    KKHAN
    Participant

    Look at link below..

    Pastebin

    #174688
    KKHAN
    Participant

    @Senff

    Nope that wouldint work console error log

    http://localhost:63342/includes/css/style.css

    it complete misses the MYSITE folder.

    #174691
    chrisburton
    Participant

    @KKHAN Ok, wait a second. What file are you pasting that in?

    It might also help if you paste the path to where the .css file is you’re trying to include and also the path to the .php file you are having trouble getting the css to work in.

    #174695
    KKHAN
    Participant

    I am pasting it in the mysite/includes/head.php file.

    Which gets included in the

    mysite/includes/overall/overallHeader.php file

    which gets included in the

    mysite/profile/dashboard.php file and
    mysite/index.php file

    #174707
    chrisburton
    Participant

    @KKHAN Can you paste what is inside head.php and /overall/overllHeader.php on pastebin? Preferably two separate ones.

    If you’re saying that the following is correct but not applying the CSS:

    <link rel="stylesheet" type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"].'/includes/css/style.css'; ?>;">
    

    I would ask you to view the page source and click the link that outputs that and tell me if it directs you to the CSS file.

    If it does, I’m not exactly understanding your problem. Are you trying to say that it only works within a specific directory and nothing deeper?

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