Jump to content

shah

Members
  • Posts

    52
  • Joined

  • Last visited

    Never

Posts posted by shah

  1. Okay, here is a snapshot of my code.........

     

    before posting the code, let me give you the folder structure again....

     

                            Parent Directory (index.php)

                                      -

                                      -

                                      -

                                      -

                          - - - - - - - - - - - - - - - - - - - - - - -

                          -                                                  - 

                          -                                                  -

                    Includes                                            CSS

    (config.php,header.php,footer.php)                  (stylesheet.css)

     

     

    The stylesheet.css simple contains the CSS layout which could be used in other files.

     

    The code of config.php is given below (according to the folder strcuture given above)

     

    <?php

        $dbhost = "localhost";

        $dbuser = "root";

        $dbpassword = "";

        $dbdatabase = "blogtastic";

        $config_blogname = "MC's Home";

        $config_author = "Syed Arif Ullah Shah";

        $config_basedir = "http://127.0.0.1/sites/Myblog/";

    ?>

     

    the code of the header.php is given below (according to the folder structure)

     

    <?php

    require_once'config.php';

    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <title><?php echo $config_blogname; ?></title>

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

    </head>

    <body>

    <div id="header">

    <h1><?php echo $config_blogname; ?></h1>

    [<a href="index.php">home</a>]

    </div>

    <div id="main">

     

    Since config.php is in the same folder, therefore i use require 'config.php'.

    Since stylesheet.css is in the CSS folder which is in the parent folder, i have to go one step above and then go to the CSS folder so i used

    "../CSS/stylesheet.css". If you know any other method to do so, kindly mention.

     

    When i run the header.php, it works absolutely fine. It displays the variables of config.php and uses the theme of stylesheet.css.

     

    Now comes the problem. in the parent directory, i have the index.php. its code is given below

     

    <?php

    require_once("./includes/header.php");

    ?>

     

    It uses the code of header.php, but theme style of stylesheet.css and variables of config.php which were used in header.php using the "require" is not used here anymore. for this purpose, i have to change the paths of files used in the header.php.

     

    change require'config.php' to require("./includes/config.php") and href="../CSS/stylesheet.css" to href="./CSS/stylesheet.css". as i have already mentioned, although the header.php is in the includes folder, but for it to be used in the index.php, we have to change the paths according to the index.php.

     

    I hope i have explained my problem. Kindly help me now.

     

    Kind Regards

    Syed Arif Ullah Shah

     

  2. Hi,

    I have a little problem with php require("header.php"). i have two php file 1) config.php and 2) header.php in includes folder. I have another Stylesheet file stylesheet.css in a folder called CSS. in the header.php file, i have used require'config.php' and linked to the style sheet through href="../CSS/stylesheet.css". Now when i have a file index.php in the parent directory and used require("./includes/header.php"), then the CSS file format of stylesheet.css and the variable of config.php are not displayed although i have included the header file in the index.php. When i investigated the issue, i have found out that when i change the include path of the header file as if it was also in the parent directory, then it works. that is when i change require'config.php' to require("./includes/config.php") and href="../CSS/stylesheet.css" to href="./CSS/stylesheet.css" then it works. as you can see, logically, the path of require should be accroding to the header.php file which is in the includes directory , but actually it is accepting the path according to the index.php file which is in the parent directory. this is actually a pain for me, because i am using the header and footer files for reusablity purpose, but it is asking me to change the path according to the caller file. I will appreciate if some one could help me. i have searched a lot on this but could not find anything. i can re explain with example if you can not understand what i mentioned above

     

    BR

    Syed Arif Ullah Shah

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.