E
E
Evgeny Ivanov2017-12-26 11:02:05
PHP
Evgeny Ivanov, 2017-12-26 11:02:05

How to set the path to a file when working with Open Server?

I want to load the site header. One header for multiple pages.
Header code (simplified. I know that you can write html in php)

//Верх страницы
echo'
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv=Content-Type content="text/html;charset=UTF-8">
<!-- Основной css файл -->
<link rel="stylesheet" type="text/css" href="'.$path_to_root_dir.'/main.css" /></head>
<body>';

Page code
$path_to_root_dir=__DIR__;
//Верх страницы - ну то есть код написанный выше
include_once ($path_to_root_dir.'/common/page_header.php');

And here problems arise.
I can't use __DIR__ in the header of the site. "If used inside an include file, then the directory of that file is returned. "((c) manual). Therefore, But this way, working in Open server, I get html code at the output
$path_to_root_dir=__DIR__;
<link rel="stylesheet" type="text/css" href="D:\OpenServer\domains\my_site.ru/main.css" />

And on this way the file does not find.
The solution would be But it's better not to do that. So how to be? How to set the path to a file when working with Open Server?
$path_to_root_dir='';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2017-12-26
@Eridani

$_SERVER['HTTP_HOST']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question