php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23911 using header location with "/" as directory doesn't work properly
Submitted: 2003-05-30 16:34 UTC Modified: 2003-05-30 16:45 UTC
From: waazup at hotmail dot com Assigned:
Status: Not a bug Package: IIS related
PHP Version: 4CVS-2003-05-30 (stable) OS: Windows XP Pro
Private report: No CVE-ID: None
 [2003-05-30 16:34 UTC] waazup at hotmail dot com
First thing is I tried this on Apache/Linux and had no problems.

I installed the CVS Windows version on my Windows XP Pro box. Today's date is May 30th, 2003.

I create a virtual directory named "phpbugheader"
inside I've put an index.php page which just says hello world.

Then I create a subdirectory called "test" and put a script in it called test.php
The location of the file on my box is:
http://192.168.0.3/phpbugheader/test/test.php
The contents of the file are as follows:
<?
// this works
//header("Location: http://192.168.0.3/phpbugheader/index.php");

// this doesn't work
header("Location: /phpbugheader/index.php");
die;
?>

As you will notice. If I try to redirect to the index page using the top header call everything works fine.
If I try using the bottom header call what happens is it redirects to the page (eg the browser displays the hello world message) the problem is that the location still shows:
http://192.168.0.3/phpbugheader/test/test.php

This only seems to happen when the location starts with / it's seems to work fine when using ../

This causes huge problems on site with relative images because the browser seems to think it's in the test directory when it should be in the base directory.
I can reproduce this bug surfing with IE6 and Mozilla1.4b and from Mozilla1.4b on a linux client.

This leads me to conclude the bug is isolated to Windows and IIS.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-30 16:42 UTC] rasmus@php.net
This has nothing to do with PHP.  Different web servers handle this differently.  According strictly to the spec (see RFC 2616 section 14.30) you have to use a full absolute URI in the location response header.  That means that using anything other than a full http://domain/foo URL is going to give you unpredictable results. 
 [2003-05-30 16:45 UTC] edink@php.net
You are violating RFC by using relative paths in header('Location: '). Now some webservers handle this, and some stick with RFC and don't. This is not a bug in PHP.

You should probably use $_SERVER['HTTP_HOST'] to construct your redirect locations which should work on all web servers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC