php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40579 $_SERVER['SERVER_PORT'] is invalid during apache redirect
Submitted: 2007-02-21 14:37 UTC Modified: 2009-05-25 18:26 UTC
Votes:5
Avg. Score:4.0 ± 1.5
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:0 (0.0%)
From: ruslan dot kyrychuk at gmail dot com Assigned:
Status: Not a bug Package: *Web Server problem
PHP Version: 5.2.1 OS: Windows 2003
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ruslan dot kyrychuk at gmail dot com
New email:
PHP Version: OS:

 

 [2007-02-21 14:37 UTC] ruslan dot kyrychuk at gmail dot com
Description:
------------
With apache redirects (mode_rewrite) then in $_SERVER['SERVER_PORT'] is always 80, even if Apache server is working on another port.

Reproduce code:
---------------
While apache redirect with following rewrite rule
RewriteRule ^(.+)$ index.php [QSA,L]
Then $_SERVER['SERVER_PORT'] is "80"
---
P.S. While 

RewriteRule ^(.+)$ index.php [E=PORT:%{SERVER_PORT},QSA,L]

then $_SERVER['REDIRECT_PORT'] is "8080"
So it looks like redirected value is sending correctly but doesn't save correctly into $_SERVER array.

Expected result:
----------------
RewriteRule ^(.+)$ index.php [QSA,L]
During redirecting 
$_SERVER['SERVER_PORT'] must be correct port.

Actual result:
--------------
$_SERVER['SERVER_PORT'] is always "80" during apache redirect.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-21 14:47 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2007-03-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-03-23 10:58 UTC] ruslan dot kyrychuk at gmail dot com
Reproduce code:
---------------
1. Configure Apache to use port 8080
2. Create .htaccess file:
Options +FollowSymLinks -Indexes
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME}  (.+)\.html
RewriteRule ^(.+)$ test.php [QSA,L]
3. Create test.php file
<?php
echo $_SERVER['SERVER_PORT'];
?>
Run http://localhost:8080/test.html
Output: 80
Run http://localhost:8080/test.php
Output: 8080
 [2007-03-23 11:10 UTC] tony2001@php.net
Works just fine here.

["SERVER_PORT"]=> string(4) "8887"
["SCRIPT_NAME"]=> string(11) "/index.html" 
 [2007-03-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-01-26 15:06 UTC] tim at timloram dot me dot uk
I am experiencing this issue with exact same symptoms. Having used mod_rewrite to redirect incoming requests to central gateway script, $_SERVER['SERVER_PORT'] is always reading '80' even if my inital URL was http://abc.com:86

Any ideas?
 [2009-03-18 13:39 UTC] peter at lvp-media dot com
This isn't a PHP-specific bug, it seems to be a problem within mod_rewrite or Apache itself. I ran into this problem as well, but was able to reproduce it with Perl and C scripts. For completeness, I'm running PHP 5.3-dev on Linux with Apache 2.2.
 [2009-05-09 21:24 UTC] vsamwarcraft3 at hotmail dot com
I have the same problem with the same symptoms. I am running a server on Ubuntu and an server on Debian.
 [2009-05-25 17:08 UTC] phpbugs at olliholliday dot co dot uk
I have the same problem.

This bug is reproducible and over a year old, if it's not going to be 
fixed is there at least a workaround?
 [2009-05-25 17:15 UTC] rasmus@php.net
This is not a PHP issue.  The Web server sets these variables.  If they are set incorrectly, file a bug with the web server folks.  PHP doesn't touch these at all, we just give you access to whatever information the web server provides.
 [2009-05-25 18:26 UTC] ruslan dot kyrychuk at gmail dot com
Yes, mono on windows produce same results - so it not PHP.

Workaround was alredy written

RewriteRule ^(.+)$ index.php [E=PORT:%{SERVER_PORT},QSA,L]

then read

$_SERVER['REDIRECT_PORT']
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC