公用PHP在不同路径的文件中被引用时,就要让公用PHP文件中的href为一个绝对url,考虑到我们的网站变化移植等因素,我们采用动态获取相对url的办法。
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<?php $nowUrlcatalog='http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strripos($_SERVER['PHP_SELF'],'/')); ?>
<link rel="stylesheet" href="<?php echo $nowUrlcatalog.'/css/index.css'; ?>">
<link rel="icon" href="<?php echo $nowUrlcatalog.'/src/image/logo.ico'; ?>" type="image/x-icon">
<link rel="shortcut icon" href="<?php echo $nowUrlcatalog.'/src/image/logo.ico'; ?>" type="image/x-icon">
</head>
<body>
<div class="top"></div>
<div id="guide">
</div>
</body>
</html>