0

Am trying to use PHP to dynamically attach same css sheet to different directory or different path on my site like this.

<!DOCTYPE html >
<html lang="en-GB">
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <?php
    if($pagename == 'login.php' || $pagename == 'register.php' || $pagename == 'admin_page.php'){?>
        <link rel="stylesheet" href="../css/style.css">
    <?php}else{?>
        <link rel="stylesheet" href="css/style.css">
    <?php}
    ?>
    </head>

Its not working when I tried it, but I really want to know if its possible.

Right here itb says "unexpected end of file"

gbenga wale
  • 359
  • 4
  • 23

1 Answers1

0
if(basename(__FILE__) == 'login.php' || basename(__FILE__) == 'register.php' || basename(__FILE__) == 'admin_page.php')
{//your link
}

should do the trick. If you need also a path, try basename($_SERVER['PHP_SELF'])

Zorak
  • 709
  • 7
  • 24