1

I have some problems with the css file when including PHP pages so I need to set the full server path here like this:

    <link rel="stylesheet" type="text/css" 
href="<?php echo $_SERVER["REQUEST_URI"];?>/css/cssfile.css">

The problem is that the css file is not in root but like this:

domain.com / folder / subfolder / css / cssfile.css

Because I run the same copy of the design and the names of the folders and subfolders are different I would like to set the full path of the css file / absolute ) but in PHP in some way

I tried the example above but is not working. What I need is something like

     <link rel="stylesheet" type="text/css" 
    href="<?php echo $_SERVER["
GET CURRENT DOMAIN / FOLDER / SUBFOLDER"];?>/engine/default.css">

Is there a way to do this?

2 Answers 2

2

The code below will give you http://example.com or https://example.com.

$domain = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];

Now you can can append your static path.

$css_url = $domain . '/my/dir/css/cssfile.css';

Hope this is helpful. Thanks!

Sign up to request clarification or add additional context in comments.

Comments

0

Declare a variable/constant as

$css_path = '../../tosuit';

Then use it in your scripts as

<link rel="stylesheet" type="text/css" 
href="<?php echo $css_path;?>/engine/default.css">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.