tags:

views:

12

answers:

1

I have defined file path like-

$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);

define('WEB_ROOT', $webRoot);

and used in my corresponding pages like-

<a href="<?php echo WEB_ROOT; ?>admin/" class="leftnav">Home</a> 
  <a href="<?php echo WEB_ROOT; ?>admin/category/" class="leftnav">Category</a>
  <a href="<?php echo WEB_ROOT; ?>admin/product/" class="leftnav">Product</a> 

but when I run this program on localhost I works fine but on server when I click on these hyper-links this gives following error-
Firefox doesn't know how to open this address, because the protocol (d) isn't associated with any program. and if I view page source the href path of these link are -

<a href="D:/Hosting/6448289/html/products/admin/category/" class="leftnav">Category</a>
  <a href="D:/Hosting/6448289/html/products/admin/product/" class="leftnav">Product</a> 
A: 

Works as designed: $_SERVER["DOCUMENT_ROOT"] is a file path, not your base URL.

The method how you define WEB_ROOT doesn't make sense to me at all. There is no way to get the web root URL from the web root path.

What you probably want is

define("WEB_ROOT", "http://".$_SERVER["SERVER_NAME"]."/");

(assuming you never need https, and you are on Apache).

Pekka