Search code examples
phphttp-redirectusing

PHP Redirect using basename(__FILE__) not working in Windows Apache server


I am building web application in Windows 7 OS running Apache Server, PHP 5.3 with MySQL.

This redirect doesn't work

    <?php
    // this is the path
    // C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Biohouse\member\public\index.php

    $path = dirname(__FILE__).'\public\index.php';
    header("location: $path");


while this working

$path = '/public/index.php'

But i will like to use the first method. Any help or suggestion will be appreciated.


Solution

  • dirname(__FILE__) gives you the path to the folder within the local file system, whereas /public/index.php is a path within the document root of the webserver/vhost of the webserver. You just cannot use __FILE__ to create URLs.