0

I have a problem connecting my profile.php

main folder

index.php
page1.php
page2.php
page3.php
server folder
css folder
include folder
user folder

server folder contains

connect.php

css folder contains

stylesheet.css

include folder contains

header.php
footer.php

user folder contains

profile.php

all the file have

include ROOT.'include/header.php';
include ROOT.'include/footer.php';

inside my header.php

<!doctype HTML>
<html>
<head>
     <link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>

i used

chdir('maindirectory');
define('ROOT', getcwd().DS);

everything works except my profile.php cant seems to load my css file. The reason why iam separating profile into user because i am using htaccess to remove '.php' and i want to allow user to search through user/'username' as well.

if i never separate, i'll have problems going to other page like example.com/page2 it will search the user instead of going to page2.

Craig
  • 1
  • When you load `profile.php` and the css file doesn't load, have you checked the browsers web inspector to see where the browser is trying (unsuccessfully) to get the css file from? I am not entirely sure from you question but it sounds like because `profile.php` is in the user folder, it is trying to find the css file at `user/css/stylesheet.css` not `css/stylesheet.css`. – JamesStewy Nov 06 '16 at 11:31
  • fixed the problem by using href ='/main/css/stylesheet.css/'; Thanks anyway! – Craig Nov 06 '16 at 12:20

2 Answers2

0

Try to include the files using $_SERVER['DOCUMENT_ROOT'] instead of ROOT or define ROOT as $_SERVER['DOCUMENT_ROOT']

0

You don't need to use chdir and define to know working folder. You can use __DIR__ constant that returns working directory (see slash before include, __DIR__ don't return last slash):

include __DIR__ . '/include/header.php';
include __DIR__ . '/include/footer.php';

In profile.php __DIR__ have root/user value. This means that yo need to do:

include __DIR__ . '/../include/header.php';
include __DIR__ . '/../include/footer.php';

If your version of PHP don't support __DIR__, you can use dirname(__FILE__) instead:

include dirname(__FILE__) . '/include/header.php';
include dirname(__FILE__) . '/include/footer.php';

If you don't know or doubt the directory you are always can echo:

echo __DIR__;
Mork
  • 365
  • 5
  • 18