Edit report at https://bugs.php.net/bug.php?id=64951&edit=1

 ID:                 64951
 Updated by:         a...@php.net
 Reported by:        a dot panek at brainsware dot org
 Summary:            SCRIPT_NAME acts strange
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Built-in web server
 Operating System:   Linux & Windows
 PHP Version:        5.4.15
-Assigned To:        
+Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Using the router script in the command line is the same as using mod_rewrite 
with apache, basically something like this

RewriteEngine On
RewriteRule ^/hellou$ /hello.php [L]

is equivalent to

php -S localhost:8080 -t. hello.php

With this, requesting /hellou under apache will result 
$_SERVER['SCRIPT_NAME'] => /hellou
__FILE__ => full path to hello.php


If you ommit the router script, you'll get the apache behaviour without 
mod_rewrite. To do so, in your example 

php -S localhost:8080 -t.

The current document root will be like a normal htdocs with apache.


Previous Comments:
------------------------------------------------------------------------
[2013-05-31 07:28:09] a dot panek at brainsware dot org

Description:
------------
When sending a request that has a file extension OR the request doesn't go to a 
index.php (a test.php, e.g.), the SCRIPT_NAME holds the URI instead of the 
actual 
current script name as documented here 
http://php.net/manual/en/reserved.variables.server.php

"Contains the current script's path. This is useful for pages which need to 
point 
to themselves. The __FILE__ constant contains the full path and filename of the 
current (i.e. included) file."

So basically the built-in server doesn't act as documented except when you use 
a 
file called "index.php" as router script and don't use a file extension in your 
URI.

I tested this on Linux and Windows resulting in the exact same behaviour.

Test script:
---------------
<?php
# index.php
#
# php -S localhost:8080 -t. index.php
#
# curl -i -X GET -H 'Accept: application/json' localhost:8080/something.json
# -> '/something.json'
# curl -i -X GET -H 'Accept: application/json' localhost:8080/something
# -> '/index.php
#
# php -S localhost:8080 -t. test.php
# -> always the uri

echo $_SERVER['SCRIPT_NAME'];

?>

Expected result:
----------------
/index.php

Actual result:
--------------
/something.json


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64951&edit=1

Reply via email to