0

So im new to php, but from what I can tell normal html should work OK in a .php file. However in my .php file it does not access my stylesheet and other assets such as pictures. I use the same lines of html in my html page and it works fine:

<head>        
    <style>
    <link rel="stylesheet" type="text/css" media="screen" href="stylesheet.css">
    <meta charset="utf-8"/>
    </style>
</head>

Looking at the network tab of the developer view, I am recieving error 404s on my images which are simple tags, but the style sheet is not even showing up.

All of this works fine in my html page and not the php page. Does php not work like this? I've seen other peoples screenshots where it looks like it does. Thanks

haco
  • 23
  • 6

1 Answers1

4

You don't need to wrap it in <style> tags:

<head>        
    <link rel="stylesheet" type="text/css" media="screen" href="stylesheet.css">
    <meta charset="utf-8"/>
</head>

Also, learn about relative and absolute paths:

Check this out: Absolute vs. relative paths

./stylesheet.css --- Same folder as file being called

stylesheet.css --- Same folder as file being called

/stylesheet.css --- Root of project (webroot)

$_SERVER['DOCUMENT_ROOT'] --- Full path of to document/web root

$_SERVER['DOCUMENT_ROOT'] . '/stylesheet.css' --- Full path to stylesheet if in document root.

Adam
  • 1,294
  • 11
  • 24
  • 2
    note: the linked paths are for UNIX based systems - `/file` on a Windows server doesn't work (because Windows Servers suck.. so much do they suck) – treyBake Aug 24 '18 at 11:42