DigitalSky
DigitalSky

Reputation: 23

Need a solution for PHP header and relative links

I think this should be a fairly simple question for anyone who knows PHP. I am more of a designer and still in the process of learning PHP.

I have a site I built which includes a PHP header and footer include. In the header file (which is used by ALL pages in the site) I have links to CSS files, JavaScript files, etc.

Right now I am using this solution for the links and includes in the header...

http://<?php echo $_SERVER['SERVER_NAME']; ?>/css/style.css

The issue with that is that some of the pages in the site are SSL pages and need to use a HTTPS prefix, not HTTP. That being said, I'm wondering if there is a simple way to link to CSS files, JavaScripts, images, etc. within the header file other than what I'm currently using?

Upvotes: 0

Views: 739

Answers (2)

Chris G.
Chris G.

Reputation: 3981

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

If that won't work for you, write a PHP function.

function base_url()
{
    if($_SERVER['HTTPS'])
        return "https://mysite.com";
    else
        return "http://mysite.com";
}

and in your html code.

<a href="<?php echo base_url(); ?>/css/ssl_stylesheet.css">

Upvotes: 2

blockhead
blockhead

Reputation: 9705

Or you can use a relative protocol: //<?php echo $_SERVER['SERVER_NAME']; ?>/css/style.css

Upvotes: 0

Related Questions